dis 1.1.4 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0118e21d454d4ce58bcf4ad8d3abc5a5eece09f7aa425869e04853d6a6a3ea10'
4
- data.tar.gz: 9cb58ea82f314f2c615a40773fa8e3e283171bbe6e0673c9f8938324c334d7c7
3
+ metadata.gz: e3b626d4874d661f0cfbb9fca2ae7b4c8d91f4a7d3b53d50a8eef7e7e26e001b
4
+ data.tar.gz: eb0b0009f3205724f8a23b505fb0ad0e2b91bf32c2a092cff75fbe668fd9f840
5
5
  SHA512:
6
- metadata.gz: 35ad213ed5e7765c117fca8cc1b9496b348c93366996451bd44c93cadac33cd147580fd28f317ad4be83ee3db8304a4074bb53c692a96a230956aeb400ab8269
7
- data.tar.gz: 54929beef973a5c1fbfa1e938c39e0bde0a2977d577325523dcf1d4eafe824b98e64ef2ac8d1d47cd2e4717341591fc659913b3a2dddd5fe2eae8195c603ae85
6
+ metadata.gz: dc99b33278935629fa9e8b498eb17c41d26e21cbcf97251e50feee83f8fc419de7a837c1246df563dfe34b9f5fc8c19a0056286b2dc0de9053a8a170750069d4
7
+ data.tar.gz: 067f17cb21587a0a33d8a03bf16bbba1e88e56a33110c316172e888720f235c8f215ae66abe789532dc6c18fd94cea76ead18f45942141d7598dcf9d9bc7e899
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Version](https://img.shields.io/gem/v/dis.svg?style=flat)](https://rubygems.org/gems/dis)
2
- [![Build Status](https://travis-ci.org/elektronaut/dis.svg?branch=master)](https://travis-ci.org/elektronaut/dis)
2
+ ![Build](https://github.com/elektronaut/dis/workflows/Build/badge.svg)
3
3
  [![Code Climate](https://codeclimate.com/github/elektronaut/dis/badges/gpa.svg)](https://codeclimate.com/github/elektronaut/dis)
4
4
  [![Code Climate](https://codeclimate.com/github/elektronaut/dis/badges/coverage.svg)](https://codeclimate.com/github/elektronaut/dis)
5
5
  [![Inline docs](http://inch-ci.org/github/elektronaut/dis.svg)](http://inch-ci.org/github/elektronaut/dis)
@@ -17,7 +17,7 @@ your own on. If you're looking to handle image uploads, check out
17
17
  [DynamicImage](https://github.com/elektronaut/dynamic_image). It's
18
18
  built on top of Dis and handles resizing, cropping and more on demand.
19
19
 
20
- Requires Rails 4.2+.
20
+ Requires Rails 5+
21
21
 
22
22
  ## Layers
23
23
 
data/lib/dis.rb CHANGED
@@ -1,18 +1,18 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'digest/sha1'
4
- require 'fog/core'
5
- require 'fog/local'
6
- require 'active_job'
7
- require 'pmap'
8
- require 'dis/engine'
9
- require 'dis/errors'
10
- require 'dis/jobs'
11
- require 'dis/layer'
12
- require 'dis/layers'
13
- require 'dis/model'
14
- require 'dis/storage'
15
- require 'dis/validations'
3
+ require "digest/sha1"
4
+ require "fog/core"
5
+ require "fog/local"
6
+ require "active_job"
7
+ require "pmap"
8
+ require "dis/engine"
9
+ require "dis/errors"
10
+ require "dis/jobs"
11
+ require "dis/layer"
12
+ require "dis/layers"
13
+ require "dis/model"
14
+ require "dis/storage"
15
+ require "dis/validations"
16
16
 
17
17
  module Dis
18
18
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  class Engine < ::Rails::Engine
@@ -1,11 +1,15 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Errors
5
5
  class Error < StandardError; end
6
+
6
7
  class ReadOnlyError < Dis::Errors::Error; end
8
+
7
9
  class NoLayersError < Dis::Errors::Error; end
10
+
8
11
  class NotFoundError < Dis::Errors::Error; end
12
+
9
13
  class NoDataError < Dis::Errors::Error; end
10
14
  end
11
15
  end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'dis/jobs/delete'
4
- require 'dis/jobs/store'
5
- require 'dis/jobs/change_type'
3
+ require "dis/jobs/delete"
4
+ require "dis/jobs/store"
5
+ require "dis/jobs/change_type"
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Jobs
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Jobs
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Jobs
@@ -12,6 +12,10 @@ module Dis
12
12
 
13
13
  def perform(type, key)
14
14
  Dis::Storage.delayed_store(type, key)
15
+ rescue Dis::Errors::NotFoundError
16
+ Rails.logger.warn(
17
+ "Delayed store failed, object not found: #{[type, key].inspect}"
18
+ )
15
19
  end
16
20
  end
17
21
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  # = Dis Layer
@@ -94,6 +94,7 @@ module Dis
94
94
  # is readonly.
95
95
  def store(type, key, file)
96
96
  raise Dis::Errors::ReadOnlyError if readonly?
97
+
97
98
  store!(type, key, file)
98
99
  end
99
100
 
@@ -101,7 +102,13 @@ module Dis
101
102
  #
102
103
  # layer.existing("documents", keys)
103
104
  def existing(type, keys)
104
- list = directory(type, keys.first).files.map(&:key)
105
+ return [] if keys.empty?
106
+
107
+ list = []
108
+ directory(type, keys.first).files.each do |file|
109
+ list << file.key
110
+ end
111
+
105
112
  keys.select { |key| list.include?(key_component(type, key)) }
106
113
  end
107
114
 
@@ -109,8 +116,7 @@ module Dis
109
116
  #
110
117
  # layer.exists?("documents", key)
111
118
  def exists?(type, key)
112
- if directory(type, key) &&
113
- directory(type, key).files.head(key_component(type, key))
119
+ if directory(type, key)&.files&.head(key_component(type, key))
114
120
  true
115
121
  else
116
122
  false
@@ -123,6 +129,7 @@ module Dis
123
129
  def get(type, key)
124
130
  dir = directory(type, key)
125
131
  return unless dir
132
+
126
133
  dir.files.get(key_component(type, key))
127
134
  end
128
135
 
@@ -134,6 +141,7 @@ module Dis
134
141
  # Raises an error if the layer is readonly.
135
142
  def delete(type, key)
136
143
  raise Dis::Errors::ReadOnlyError if readonly?
144
+
137
145
  delete!(type, key)
138
146
  end
139
147
 
@@ -151,15 +159,16 @@ module Dis
151
159
  end
152
160
 
153
161
  def directory_component(_type, _key)
154
- path || ''
162
+ path || ""
155
163
  end
156
164
 
157
165
  def key_component(type, key)
158
- [type, key[0...2], key[2..key.length]].compact.join('/')
166
+ [type, key[0...2], key[2..key.length]].compact.join("/")
159
167
  end
160
168
 
161
169
  def delete!(type, key)
162
170
  return false unless exists?(type, key)
171
+
163
172
  get(type, key).destroy
164
173
  end
165
174
 
@@ -170,7 +179,7 @@ module Dis
170
179
  def directory!(type, key)
171
180
  dir = directory(type, key)
172
181
  dir ||= connection.directories.create(
173
- key: directory_component(type, key),
182
+ key: directory_component(type, key),
174
183
  public: public?
175
184
  )
176
185
  dir
@@ -178,16 +187,17 @@ module Dis
178
187
 
179
188
  def store!(type, key, file)
180
189
  return get(type, key) if exists?(type, key)
190
+
181
191
  file.rewind if file.respond_to?(:rewind)
182
192
  directory!(type, key).files.create(
183
- key: key_component(type, key),
184
- body: (file.is_a?(Fog::Model) ? file.body : file),
193
+ key: key_component(type, key),
194
+ body: (file.is_a?(Fog::Model) ? file.body : file),
185
195
  public: public?
186
196
  )
187
197
  end
188
198
 
189
199
  def path
190
- @path && !@path.empty? ? @path : nil
200
+ @path.presence
191
201
  end
192
202
  end
193
203
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  # = Dis Layers
@@ -22,8 +22,8 @@ module Dis
22
22
  end
23
23
 
24
24
  # Iterates over the layers.
25
- def each
26
- @layers.each { |layer| yield layer }
25
+ def each(&block)
26
+ @layers.each { |layer| block.call(layer) }
27
27
  end
28
28
 
29
29
  # Returns a new instance containing only the delayed layers.
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'dis/model/class_methods'
4
- require 'dis/model/data'
3
+ require "dis/model/class_methods"
4
+ require "dis/model/data"
5
5
 
6
6
  module Dis
7
7
  # = Dis Model
@@ -103,7 +103,7 @@ module Dis
103
103
  # <tt>content_hash</tt> to nil.
104
104
  def data=(raw_data)
105
105
  new_data = Dis::Model::Data.new(self, raw_data)
106
- attribute_will_change!('data') unless new_data == dis_data
106
+ attribute_will_change!("data") unless new_data == dis_data
107
107
  @dis_data = new_data
108
108
  dis_set :content_hash, if raw_data.nil?
109
109
  nil
@@ -115,7 +115,7 @@ module Dis
115
115
 
116
116
  # Returns true if the data has been changed since the object was last saved.
117
117
  def data_changed?
118
- changes.include?('data')
118
+ changes.include?("data")
119
119
  end
120
120
 
121
121
  def dis_stored?
@@ -135,6 +135,7 @@ module Dis
135
135
 
136
136
  def cleanup_data
137
137
  return if @previous_content_hash.blank?
138
+
138
139
  dis_data.expire(@previous_content_hash)
139
140
  @previous_content_hash = nil
140
141
  end
@@ -167,7 +168,7 @@ module Dis
167
168
 
168
169
  # We don't want the data column when doing a partial write.
169
170
  def keys_for_partial_write
170
- super.reject { |a| a == 'data' }
171
+ super.reject { |a| a == "data" }
171
172
  end
172
173
  end
173
174
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Model
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Model
@@ -26,7 +26,7 @@ module Dis
26
26
 
27
27
  # Returns the data as a binary string.
28
28
  def read
29
- @cached ||= read_from(closest)
29
+ @read ||= read_from(closest)
30
30
  end
31
31
 
32
32
  # Will be true if data has been explicitely set.
@@ -60,6 +60,7 @@ module Dis
60
60
  # Stores the data. Returns a hash of the content for reference.
61
61
  def store!
62
62
  raise Dis::Errors::NoDataError unless raw?
63
+
63
64
  Dis::Storage.store(storage_type, raw)
64
65
  end
65
66
 
@@ -83,6 +84,7 @@ module Dis
83
84
 
84
85
  def read_from(object)
85
86
  return nil unless object
87
+
86
88
  if object.respond_to?(:body)
87
89
  object.body
88
90
  elsif object.respond_to?(:read)
@@ -104,14 +106,13 @@ module Dis
104
106
  end
105
107
 
106
108
  def stored?
107
- @record.dis_stored? && !content_hash.blank?
109
+ content_hash.present? &&
110
+ (@record.dis_stored? ||
111
+ Dis::Storage.exists?(storage_type, content_hash))
108
112
  end
109
113
 
110
114
  def stored
111
- Dis::Storage.get(
112
- storage_type,
113
- content_hash
114
- )
115
+ Dis::Storage.get(storage_type, content_hash)
115
116
  end
116
117
 
117
118
  attr_reader :raw
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  # = Dis Storage
@@ -107,9 +107,7 @@ module Dis
107
107
  fetch_count += 1
108
108
  layer.get(type, key)
109
109
  end.call
110
- end
111
-
112
- raise Dis::Errors::NotFoundError unless result
110
+ end || raise(Dis::Errors::NotFoundError)
113
111
 
114
112
  store_immediately!(type, result) if fetch_count > 1
115
113
  result
@@ -1,3 +1,3 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'dis/validations/data_presence'
3
+ require "dis/validations/data_presence"
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Validations
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
- VERSION = '1.1.4'.freeze
4
+ VERSION = "1.1.9"
5
5
  end
@@ -1,16 +1,16 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
4
- require 'rails/generators/rails/model/model_generator'
3
+ require "rails/generators"
4
+ require "rails/generators/rails/model/model_generator"
5
5
 
6
6
  module Dis
7
7
  module Generators
8
8
  class InstallGenerator < Rails::Generators::Base
9
- desc 'Creates the Dis initializer'
10
- source_root File.expand_path('../templates', __FILE__)
9
+ desc "Creates the Dis initializer"
10
+ source_root File.expand_path("templates", __dir__)
11
11
 
12
12
  def create_initializer
13
- template 'initializer.rb', File.join('config', 'initializers', 'dis.rb')
13
+ template "initializer.rb", File.join("config", "initializers", "dis.rb")
14
14
  end
15
15
  end
16
16
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Creates a local storage layer in db/dis:
4
6
 
5
7
  Dis::Storage.layers << Dis::Layer.new(
6
- Fog::Storage.new(provider: 'Local', local_root: Rails.root.join('db', 'dis')),
8
+ Fog::Storage.new(provider: "Local", local_root: Rails.root.join("db/dis")),
7
9
  path: Rails.env
8
10
  )
9
11
 
@@ -1,12 +1,12 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
4
- require 'rails/generators/rails/model/model_generator'
3
+ require "rails/generators"
4
+ require "rails/generators/rails/model/model_generator"
5
5
 
6
6
  module Dis
7
7
  module Generators
8
8
  class ModelGenerator < Rails::Generators::ModelGenerator
9
- desc 'Creates a Dis model'
9
+ desc "Creates a Dis model"
10
10
 
11
11
  def initialize(args, *options)
12
12
  super(inject_dis_attributes(args), *options)
@@ -14,7 +14,7 @@ module Dis
14
14
 
15
15
  def add_model_extension
16
16
  inject_into_file(
17
- File.join('app/models', class_path, "#{file_name}.rb"),
17
+ File.join("app/models", class_path, "#{file_name}.rb"),
18
18
  after: "ActiveRecord::Base\n"
19
19
  ) do
20
20
  " include Dis::Model\n"
@@ -32,12 +32,12 @@ module Dis
32
32
  end
33
33
 
34
34
  def dis_attributes
35
- %w(
35
+ %w[
36
36
  content_hash:string
37
37
  content_type:string
38
38
  content_length:integer
39
39
  filename:string
40
- )
40
+ ]
41
41
  end
42
42
  end
43
43
  end
@@ -1,15 +1,15 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  namespace :dis do
4
- desc 'Check stuff'
4
+ desc "Check stuff"
5
5
  task consistency_check: :environment do
6
- unless ENV['MODELS']
6
+ unless ENV["MODELS"]
7
7
  puts "Usage: #{$PROGRAM_NAME} dis:consistency_check " \
8
- 'MODELS=Avatar,Document'
8
+ "MODELS=Avatar,Document"
9
9
  exit
10
10
  end
11
11
 
12
- models = ENV['MODELS'].split(',').map(&:strip).map(&:constantize)
12
+ models = ENV["MODELS"].split(",").map(&:strip).map(&:constantize)
13
13
 
14
14
  jobs = Set.new
15
15
 
@@ -17,10 +17,7 @@ namespace :dis do
17
17
  puts "-- #{model.name} --"
18
18
 
19
19
  content_hash_attr = model.dis_attributes[:content_hash]
20
- objects = model
21
- .select(content_hash_attr)
22
- .uniq
23
- .map { |r| r.send(content_hash_attr) }
20
+ objects = model.pluck(content_hash_attr).uniq
24
21
  global_missing = objects.dup
25
22
 
26
23
  puts "Unique objects: #{objects.length}"
@@ -31,9 +28,14 @@ namespace :dis do
31
28
  existing = layer.existing(model.dis_type, objects)
32
29
  missing = objects - existing
33
30
  global_missing -= existing
34
- puts "#{existing.length} existing, #{missing.length} missing"
31
+ puts "#{existing.length} existing, #{missing.length} missing" +
32
+ (layer.readonly? ? " (read-only)" : "")
35
33
 
36
- next unless layer.delayed?
34
+ next unless layer.delayed? && !layer.readonly?
35
+
36
+ jobs += (missing - global_missing).pmap do |hash|
37
+ [model.dis_type, hash]
38
+ end.compact
37
39
  end
38
40
 
39
41
  if global_missing.any?
@@ -41,18 +43,14 @@ namespace :dis do
41
43
  pp global_missing
42
44
  end
43
45
 
44
- jobs += (objects - global_missing).pmap do |hash|
45
- [model.dis_type, hash]
46
- end.compact
47
-
48
46
  puts
49
47
  end
50
48
 
51
49
  if jobs.any?
52
50
  print "#{jobs.length} objects can be transferred to delayed layers, " \
53
51
  "queue now? (y/n) "
54
- response = STDIN.gets.chomp
55
- if response =~ /^y/i
52
+ response = $stdin.gets.chomp
53
+ if /^y/i.match?(response)
56
54
  puts "Queueing jobs..."
57
55
  jobs.each { |type, hash| Dis::Jobs::Store.perform_later(type, hash) }
58
56
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '5.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: fog-core
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +53,21 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: 1.1.0
69
55
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,19 +81,33 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec-rails
84
+ name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.5'
89
+ version: 0.17.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.5'
96
+ version: 0.17.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Dis is a Rails plugin that stores your file uploads and other binary
98
112
  blobs.
99
113
  email:
@@ -127,7 +141,7 @@ homepage: https://github.com/elektronaut/dis
127
141
  licenses:
128
142
  - MIT
129
143
  metadata: {}
130
- post_install_message:
144
+ post_install_message:
131
145
  rdoc_options: []
132
146
  require_paths:
133
147
  - lib
@@ -135,15 +149,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: 1.9.2
152
+ version: 2.4.0
139
153
  required_rubygems_version: !ruby/object:Gem::Requirement
140
154
  requirements:
141
155
  - - ">="
142
156
  - !ruby/object:Gem::Version
143
157
  version: '0'
144
158
  requirements: []
145
- rubygems_version: 3.0.1
146
- signing_key:
159
+ rubygems_version: 3.1.4
160
+ signing_key:
147
161
  specification_version: 4
148
162
  summary: A file store for your Rails app
149
163
  test_files: []