has_metadata_column 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76fe1f392ba5d8e28fcfa3961f48226ff67a7150
4
- data.tar.gz: 49a78d081bbc71cf5142918018b4af1adc9ab4b4
3
+ metadata.gz: 790f5c7a05281203980c9ba2b8320cc64128304f
4
+ data.tar.gz: aba51f2f218997b2758e4efc898c2967bfc2ca45
5
5
  SHA512:
6
- metadata.gz: 44662900d5ab1d8c6d8bd47849077bd51be7bf22bbe8f588e1545c9740da78c329a1bcd57ac0e552b38c7bba7ad3f1fb3cb771fe514235704dd24c7ce73e5f37
7
- data.tar.gz: b61ac7b2115c382ac708e6444552349247ea25f5477c56a12c61fa6fafd2144ac190dac9125a4e4831e7e2430abc184fa01907c5ff3d1643f44eb904d328415d
6
+ metadata.gz: f7702944ad2ab9f954293e010b74b39eb747a4c31629c86958f9f56c98cba640a1789c384733c91db92725502c7ebb7d9fd76cb5de3c2ec46370a210293782a7
7
+ data.tar.gz: d6c22bc4ea916c4831104d4388c3392f462abc1fd0c756eeeb31a0d98323c8c16eb793da28b3f59de10badfdc510f19dce31b2f0997362e417b95960ebee15b3
@@ -1,19 +1,19 @@
1
- # Generated by jeweler
1
+ # Generated by juwelier
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: has_metadata_column 1.1.5 ruby lib
5
+ # stub: has_metadata_column 1.1.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "has_metadata_column"
9
- s.version = "1.1.5"
8
+ s.name = "has_metadata_column".freeze
9
+ s.version = "1.1.6"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Tim Morgan"]
14
- s.date = "2014-12-20"
15
- s.description = "Reduce your table width and migration overhead by moving non-indexed columns to a separate metadata column."
16
- s.email = "git@timothymorgan.info"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Tim Morgan".freeze]
14
+ s.date = "2016-07-04"
15
+ s.description = "Reduce your table width and migration overhead by moving non-indexed columns to a separate metadata column.".freeze
16
+ s.email = "git@timothymorgan.info".freeze
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
19
  "README.md"
@@ -23,40 +23,43 @@ Gem::Specification.new do |s|
23
23
  "has_metadata_column.gemspec",
24
24
  "lib/has_metadata_column.rb"
25
25
  ]
26
- s.homepage = "http://github.com/riscfuture/has_metadata_column"
27
- s.licenses = ["MIT"]
28
- s.required_ruby_version = Gem::Requirement.new(">= 1.9")
29
- s.rubygems_version = "2.4.5"
30
- s.summary = "Schemaless metadata using JSON columns"
26
+ s.homepage = "http://github.com/riscfuture/has_metadata_column".freeze
27
+ s.licenses = ["MIT".freeze]
28
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9".freeze)
29
+ s.rubygems_version = "2.6.6".freeze
30
+ s.summary = "Schemaless metadata using JSON columns".freeze
31
31
 
32
32
  if s.respond_to? :specification_version then
33
33
  s.specification_version = 4
34
34
 
35
35
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
36
- s.add_runtime_dependency(%q<rails>, [">= 4.2"])
37
- s.add_runtime_dependency(%q<boolean>, [">= 0"])
38
- s.add_development_dependency(%q<rspec>, [">= 0"])
39
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
40
- s.add_development_dependency(%q<yard>, [">= 0"])
41
- s.add_development_dependency(%q<redcarpet>, [">= 0"])
42
- s.add_development_dependency(%q<jeweler>, [">= 0"])
36
+ s.add_runtime_dependency(%q<rails>.freeze, [">= 5.0"])
37
+ s.add_runtime_dependency(%q<boolean>.freeze, [">= 0"])
38
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
39
+ s.add_development_dependency(%q<sqlite3>.freeze, [">= 0"])
40
+ s.add_development_dependency(%q<yard>.freeze, [">= 0"])
41
+ s.add_development_dependency(%q<redcarpet>.freeze, [">= 0"])
42
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
43
+ s.add_development_dependency(%q<activemodel-serializers-xml>.freeze, [">= 0"])
43
44
  else
44
- s.add_dependency(%q<rails>, [">= 4.2"])
45
- s.add_dependency(%q<boolean>, [">= 0"])
46
- s.add_dependency(%q<rspec>, [">= 0"])
47
- s.add_dependency(%q<sqlite3>, [">= 0"])
48
- s.add_dependency(%q<yard>, [">= 0"])
49
- s.add_dependency(%q<redcarpet>, [">= 0"])
50
- s.add_dependency(%q<jeweler>, [">= 0"])
45
+ s.add_dependency(%q<rails>.freeze, [">= 5.0"])
46
+ s.add_dependency(%q<boolean>.freeze, [">= 0"])
47
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
48
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
49
+ s.add_dependency(%q<yard>.freeze, [">= 0"])
50
+ s.add_dependency(%q<redcarpet>.freeze, [">= 0"])
51
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
52
+ s.add_dependency(%q<activemodel-serializers-xml>.freeze, [">= 0"])
51
53
  end
52
54
  else
53
- s.add_dependency(%q<rails>, [">= 4.2"])
54
- s.add_dependency(%q<boolean>, [">= 0"])
55
- s.add_dependency(%q<rspec>, [">= 0"])
56
- s.add_dependency(%q<sqlite3>, [">= 0"])
57
- s.add_dependency(%q<yard>, [">= 0"])
58
- s.add_dependency(%q<redcarpet>, [">= 0"])
59
- s.add_dependency(%q<jeweler>, [">= 0"])
55
+ s.add_dependency(%q<rails>.freeze, [">= 5.0"])
56
+ s.add_dependency(%q<boolean>.freeze, [">= 0"])
57
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
58
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
59
+ s.add_dependency(%q<yard>.freeze, [">= 0"])
60
+ s.add_dependency(%q<redcarpet>.freeze, [">= 0"])
61
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
62
+ s.add_dependency(%q<activemodel-serializers-xml>.freeze, [">= 0"])
60
63
  end
61
64
  end
62
65
 
@@ -19,6 +19,8 @@ end
19
19
  module HasMetadataColumn
20
20
  extend ActiveSupport::Concern
21
21
 
22
+ included { prepend Extensions }
23
+
22
24
  # Valid values for the `:type` option.
23
25
  TYPES = [String, Fixnum, Integer, Float, Hash, Array, TrueClass, FalseClass, Boolean, NilClass, Date, Time]
24
26
 
@@ -102,15 +104,6 @@ module HasMetadataColumn
102
104
  self.metadata_column_fields = fields.deep_clone
103
105
  class_attribute :metadata_column
104
106
  self.metadata_column = column || :metadata
105
-
106
- # alias_method_chain :changed_attributes, :metadata_column
107
- alias_method_chain :attribute_will_change!, :metadata_column
108
- alias_method_chain :attribute_method?, :metadata
109
- alias_method_chain :attribute, :metadata
110
- alias_method_chain :attribute_before_type_cast, :metadata
111
- alias_method_chain :attribute=, :metadata
112
- alias_method_chain :query_attribute, :metadata
113
- alias_method_chain :keys_for_partial_write, :metadata
114
107
  else
115
108
  raise "Cannot redefine existing metadata column #{self.metadata_column}" if column && column != self.metadata_column
116
109
  if metadata_column_fields.slice(*fields.keys) != fields
@@ -172,10 +165,10 @@ module HasMetadataColumn
172
165
 
173
166
  # @private
174
167
  def as_json(options={})
175
- options ||= Hash.new # the JSON encoder can sometimes give us nil options?
176
- options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
177
- metadata = self.class.metadata_column_fields.keys
178
- metadata &= Array.wrap(options[:only]) if options[:only]
168
+ options ||= Hash.new # the JSON encoder can sometimes give us nil options?
169
+ options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
170
+ metadata = self.class.metadata_column_fields.keys
171
+ metadata &= Array.wrap(options[:only]) if options[:only]
179
172
  metadata -= Array.wrap(options[:except])
180
173
  options[:methods] = Array.wrap(options[:methods]) + metadata
181
174
  super options
@@ -183,9 +176,9 @@ module HasMetadataColumn
183
176
 
184
177
  # @private
185
178
  def to_xml(options={})
186
- options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
187
- metadata = self.class.metadata_column_fields.keys
188
- metadata &= Array.wrap(options[:only]) if options[:only]
179
+ options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
180
+ metadata = self.class.metadata_column_fields.keys
181
+ metadata &= Array.wrap(options[:only]) if options[:only]
189
182
  metadata -= Array.wrap(options[:except])
190
183
  options[:methods] = Array.wrap(options[:methods]) + metadata
191
184
  super options
@@ -218,7 +211,7 @@ module HasMetadataColumn
218
211
  end
219
212
  end
220
213
 
221
- super(pairs - fake_attributes)
214
+ super(pairs.except(*fake_attributes.keys))
222
215
  end
223
216
 
224
217
  # @private
@@ -229,19 +222,12 @@ module HasMetadataColumn
229
222
  # @private
230
223
  def reload(*)
231
224
  super.tap do
232
- @_metadata_hash = nil
225
+ @_metadata_hash = nil
233
226
  end
234
227
  end
235
228
 
236
229
  private
237
230
 
238
- def attribute_will_change_with_metadata_column!(attr)
239
- unless attribute_names.include?(attr)
240
- send :"#{self.class.metadata_column}_will_change!"
241
- end
242
- attribute_will_change_without_metadata_column! attr
243
- end
244
-
245
231
  def _metadata_hash
246
232
  @_metadata_hash ||= begin
247
233
  send(self.class.metadata_column) ? JSON.parse(send(self.class.metadata_column)) : {}
@@ -250,52 +236,61 @@ module HasMetadataColumn
250
236
  end
251
237
  end
252
238
 
253
- ## ATTRIBUTE MATCHER METHODS
239
+ module Extensions
240
+ def attribute_will_change!(attr)
241
+ unless attribute_names.include?(attr)
242
+ send :"#{self.class.metadata_column}_will_change!"
243
+ end
244
+ super
245
+ end
254
246
 
255
- def attribute_with_metadata(attr)
256
- return attribute_without_metadata(attr) unless self.class.metadata_column_fields.include?(attr.to_sym)
247
+ ## ATTRIBUTE MATCHER METHODS
257
248
 
258
- options = self.class.metadata_column_fields[attr.to_sym] || {}
259
- default = options.include?(:default) ? options[:default] : nil
260
- _metadata_hash.include?(attr) ? HasMetadataColumn.metadata_typecast(_metadata_hash[attr], options[:type]) : default
261
- end
249
+ def attribute(attr)
250
+ return super unless self.class.metadata_column_fields.include?(attr.to_sym)
262
251
 
263
- def attribute_before_type_cast_with_metadata(attr)
264
- return attribute_before_type_cast_without_metadata(attr) unless self.class.metadata_column_fields.include?(attr.to_sym)
265
- options = self.class.metadata_column_fields[attr.to_sym] || {}
266
- default = options.include?(:default) ? options[:default] : nil
267
- _metadata_hash.include?(attr) ? _metadata_hash[attr] : default
268
- end
252
+ options = self.class.metadata_column_fields[attr.to_sym] || {}
253
+ default = options.include?(:default) ? options[:default] : nil
254
+ _metadata_hash.include?(attr) ? HasMetadataColumn.metadata_typecast(_metadata_hash[attr], options[:type]) : default
255
+ end
269
256
 
270
- def _attribute_with_metadata(attr)
271
- return _attribute_without_metadata(attr) unless self.class.metadata_column_fields.include?(attr.to_sym)
272
- attribute_with_metadata attr
273
- end
257
+ def attribute_before_type_cast(attr)
258
+ return super unless self.class.metadata_column_fields.include?(attr.to_sym)
259
+ options = self.class.metadata_column_fields[attr.to_sym] || {}
260
+ default = options.include?(:default) ? options[:default] : nil
261
+ _metadata_hash.include?(attr) ? _metadata_hash[attr] : default
262
+ end
274
263
 
275
- def attribute_with_metadata=(attr, value)
276
- return send(:attribute_without_metadata=, attr, value) unless self.class.metadata_column_fields.include?(attr.to_sym)
264
+ def _attribute(attr)
265
+ return super unless self.class.metadata_column_fields.include?(attr.to_sym)
266
+ attribute attr
267
+ end
277
268
 
278
- attribute_will_change! attr
279
- old = _metadata_hash[attr.to_s]
280
- send :"#{self.class.metadata_column}=", _metadata_hash.merge(attr.to_s => value).to_json
281
- @_metadata_hash = nil
282
- value
283
- end
269
+ def attribute=(attr, value)
270
+ return super unless self.class.metadata_column_fields.include?(attr.to_sym)
284
271
 
285
- def query_attribute_with_metadata(attr)
286
- return query_attribute_without_metadata(attr) unless self.class.metadata_column_fields.include?(attr.to_sym)
287
- return false unless (value = send(attr))
288
- options = self.class.metadata_column_fields[attr.to_sym] || {}
289
- type = options[:type] || String
290
- return !value.to_i.zero? if type.ancestors.include?(Numeric)
291
- return !value.blank?
292
- end
272
+ attribute_will_change! attr
273
+ old = _metadata_hash[attr.to_s]
274
+ send :"#{self.class.metadata_column}=", _metadata_hash.merge(attr.to_s => value).to_json
275
+ @_metadata_hash = nil
276
+ value
277
+ end
293
278
 
294
- def attribute_method_with_metadata?(attr)
295
- self.class.metadata_column_fields.include?(attr.to_sym) || attribute_method_without_metadata?(attr)
296
- end
279
+ def query_attribute(attr)
280
+ return super unless self.class.metadata_column_fields.include?(attr.to_sym)
281
+ return false unless (value = send(attr))
282
+ options = self.class.metadata_column_fields[attr.to_sym] || {}
283
+ type = options[:type] || String
284
+ return !value.to_i.zero? if type.ancestors.include?(Numeric)
285
+ return !value.blank?
286
+ end
297
287
 
298
- def keys_for_partial_write_with_metadata
299
- keys_for_partial_write_without_metadata - self.class.metadata_column_fields.keys.map(&:to_s)
288
+ def attribute_method?(attr)
289
+ self.class.metadata_column_fields.include?(attr.to_sym) || super
290
+ end
291
+
292
+ def keys_for_partial_write
293
+ super - self.class.metadata_column_fields.keys.map(&:to_s)
294
+ end
300
295
  end
301
296
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_metadata_column
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
  - Tim Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-20 00:00:00.000000000 Z
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: boolean
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +95,21 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: jeweler
98
+ name: juwelier
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'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activemodel-serializers-xml
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -141,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
155
  version: '0'
142
156
  requirements: []
143
157
  rubyforge_project:
144
- rubygems_version: 2.4.5
158
+ rubygems_version: 2.6.6
145
159
  signing_key:
146
160
  specification_version: 4
147
161
  summary: Schemaless metadata using JSON columns