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 +4 -4
- data/has_metadata_column.gemspec +40 -37
- data/lib/has_metadata_column.rb +58 -63
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 790f5c7a05281203980c9ba2b8320cc64128304f
|
4
|
+
data.tar.gz: aba51f2f218997b2758e4efc898c2967bfc2ca45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7702944ad2ab9f954293e010b74b39eb747a4c31629c86958f9f56c98cba640a1789c384733c91db92725502c7ebb7d9fd76cb5de3c2ec46370a210293782a7
|
7
|
+
data.tar.gz: d6c22bc4ea916c4831104d4388c3392f462abc1fd0c756eeeb31a0d98323c8c16eb793da28b3f59de10badfdc510f19dce31b2f0997362e417b95960ebee15b3
|
data/has_metadata_column.gemspec
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
# Generated by
|
1
|
+
# Generated by juwelier
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: has_metadata_column 1.1.
|
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.
|
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 = "
|
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.
|
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
|
37
|
-
s.add_runtime_dependency(%q<boolean
|
38
|
-
s.add_development_dependency(%q<rspec
|
39
|
-
s.add_development_dependency(%q<sqlite3
|
40
|
-
s.add_development_dependency(%q<yard
|
41
|
-
s.add_development_dependency(%q<redcarpet
|
42
|
-
s.add_development_dependency(%q<
|
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
|
45
|
-
s.add_dependency(%q<boolean
|
46
|
-
s.add_dependency(%q<rspec
|
47
|
-
s.add_dependency(%q<sqlite3
|
48
|
-
s.add_dependency(%q<yard
|
49
|
-
s.add_dependency(%q<redcarpet
|
50
|
-
s.add_dependency(%q<
|
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
|
54
|
-
s.add_dependency(%q<boolean
|
55
|
-
s.add_dependency(%q<rspec
|
56
|
-
s.add_dependency(%q<sqlite3
|
57
|
-
s.add_dependency(%q<yard
|
58
|
-
s.add_dependency(%q<redcarpet
|
59
|
-
s.add_dependency(%q<
|
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
|
|
data/lib/has_metadata_column.rb
CHANGED
@@ -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
|
176
|
-
options[:except]
|
177
|
-
metadata
|
178
|
-
metadata
|
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]
|
187
|
-
metadata
|
188
|
-
metadata
|
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
|
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
|
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
|
-
|
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
|
-
|
256
|
-
return attribute_without_metadata(attr) unless self.class.metadata_column_fields.include?(attr.to_sym)
|
247
|
+
## ATTRIBUTE MATCHER METHODS
|
257
248
|
|
258
|
-
|
259
|
-
|
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
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
276
|
-
|
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
|
-
|
279
|
-
|
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
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
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
|
-
|
295
|
-
|
296
|
-
|
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
|
-
|
299
|
-
|
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.
|
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:
|
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: '
|
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: '
|
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:
|
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.
|
158
|
+
rubygems_version: 2.6.6
|
145
159
|
signing_key:
|
146
160
|
specification_version: 4
|
147
161
|
summary: Schemaless metadata using JSON columns
|