dis 1.1.5 → 1.1.6

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: 25df4cff8fae7044ae9409c77cde74fb8dcd48ce2c36dc07f87e662223752bd6
4
- data.tar.gz: 1f7c68208264c977f5733c6a7553728d0dac92c6d47a0ea97aa756e5632e1621
3
+ metadata.gz: 75c6c1d614d13eaa8ae3b3fd30762e1a22069fb60629ebc2bb6b396caf72a25e
4
+ data.tar.gz: fa6552876ae2e87d50416d004b34ee9039ceabfe459a2dbff899028650346a43
5
5
  SHA512:
6
- metadata.gz: 6178ecc70a1ba31c9dff52389ab42b9b2f5bebcd7a0d47a89f95292f0b87706110b1e08afb38431298cd038ee81b85f8ea20be6e32753804f4215eb4083d4cde
7
- data.tar.gz: b128f8665c386e720a8d9413a56a6a8123454716da2e2efa54f0e14c9336aa3c7df5a18eef309af6a3658625b6f08477648617aa3856586259d6db3395fca839
6
+ metadata.gz: 3e299491b62a599f7e0cb16e2de1ad67152e96fd6496b58e01d407f728c3739530822626c551405fd06585f0d7590ea7ca438a2bf0774770776d4ce4dc8b288f
7
+ data.tar.gz: 78e7d8efea50cff8bc50d4a412166b2f814644781e2c86b99041a554eb29bab70ff81f61f0898039b9c108072669ecbe17247aed3706805fdada761e51345941
data/README.md CHANGED
@@ -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,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Dis
4
4
  module Errors
@@ -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
@@ -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,6 +102,8 @@ module Dis
101
102
  #
102
103
  # layer.existing("documents", keys)
103
104
  def existing(type, keys)
105
+ return [] if keys.empty?
106
+
104
107
  list = []
105
108
  directory(type, keys.first).files.each do |file|
106
109
  list << file.key
@@ -113,8 +116,7 @@ module Dis
113
116
  #
114
117
  # layer.exists?("documents", key)
115
118
  def exists?(type, key)
116
- if directory(type, key) &&
117
- directory(type, key).files.head(key_component(type, key))
119
+ if directory(type, key)&.files&.head(key_component(type, key))
118
120
  true
119
121
  else
120
122
  false
@@ -127,6 +129,7 @@ module Dis
127
129
  def get(type, key)
128
130
  dir = directory(type, key)
129
131
  return unless dir
132
+
130
133
  dir.files.get(key_component(type, key))
131
134
  end
132
135
 
@@ -138,6 +141,7 @@ module Dis
138
141
  # Raises an error if the layer is readonly.
139
142
  def delete(type, key)
140
143
  raise Dis::Errors::ReadOnlyError if readonly?
144
+
141
145
  delete!(type, key)
142
146
  end
143
147
 
@@ -155,15 +159,16 @@ module Dis
155
159
  end
156
160
 
157
161
  def directory_component(_type, _key)
158
- path || ''
162
+ path || ""
159
163
  end
160
164
 
161
165
  def key_component(type, key)
162
- [type, key[0...2], key[2..key.length]].compact.join('/')
166
+ [type, key[0...2], key[2..key.length]].compact.join("/")
163
167
  end
164
168
 
165
169
  def delete!(type, key)
166
170
  return false unless exists?(type, key)
171
+
167
172
  get(type, key).destroy
168
173
  end
169
174
 
@@ -174,7 +179,7 @@ module Dis
174
179
  def directory!(type, key)
175
180
  dir = directory(type, key)
176
181
  dir ||= connection.directories.create(
177
- key: directory_component(type, key),
182
+ key: directory_component(type, key),
178
183
  public: public?
179
184
  )
180
185
  dir
@@ -182,16 +187,17 @@ module Dis
182
187
 
183
188
  def store!(type, key, file)
184
189
  return get(type, key) if exists?(type, key)
190
+
185
191
  file.rewind if file.respond_to?(:rewind)
186
192
  directory!(type, key).files.create(
187
- key: key_component(type, key),
188
- 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),
189
195
  public: public?
190
196
  )
191
197
  end
192
198
 
193
199
  def path
194
- @path && !@path.empty? ? @path : nil
200
+ @path.presence
195
201
  end
196
202
  end
197
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
@@ -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,7 +106,7 @@ module Dis
104
106
  end
105
107
 
106
108
  def stored?
107
- @record.dis_stored? && !content_hash.blank?
109
+ @record.dis_stored? && content_hash.present?
108
110
  end
109
111
 
110
112
  def stored
@@ -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.5'.freeze
4
+ VERSION = "1.1.6"
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
 
@@ -52,7 +52,7 @@ namespace :dis do
52
52
  print "#{jobs.length} objects can be transferred to delayed layers, " \
53
53
  "queue now? (y/n) "
54
54
  response = STDIN.gets.chomp
55
- if response =~ /^y/i
55
+ if /^y/i.match?(response)
56
56
  puts "Queueing jobs..."
57
57
  jobs.each { |type, hash| Dis::Jobs::Store.perform_later(type, hash) }
58
58
  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.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-08-17 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,19 +53,19 @@ 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
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - ">"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
61
+ version: '5.0'
62
+ type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - ">"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: '5.0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rspec-rails
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,20 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
97
  description: Dis is a Rails plugin that stores your file uploads and other binary
98
98
  blobs.
99
99
  email:
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 1.9.2
138
+ version: 2.4.0
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="