has_metadata_column 1.0.3 → 1.1.0

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.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Has Metadata Column -- Keep your tables narrow
4
4
  | | |
5
5
  |:------------|:--------------------------------|
6
6
  | **Author** | Tim Morgan |
7
- | **Version** | 1.0.2 (Oct 4, 2012) |
7
+ | **Version** | 1.1.0 (Jul 9, 2013) |
8
8
  | **License** | Released under the MIT License. |
9
9
 
10
10
  About
@@ -32,7 +32,7 @@ does not get its little fingers all up in ActiveRecord's business.
32
32
 
33
33
  h2. Installation
34
34
 
35
- **Important Note:** This gem is only compatible with Ruby 1.9 and Rails 3.0.
35
+ **Important Note:** This gem is only compatible with Ruby 1.9 and Rails 4.0.
36
36
 
37
37
  Merely add the gem to your Rails project's `Gemfile`:
38
38
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "has_metadata_column"
8
- s.version = "1.0.3"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tim Morgan"]
12
- s.date = "2012-12-14"
12
+ s.date = "2013-07-09"
13
13
  s.description = "Reduce your table width and migration overhead by moving non-indexed columns to a separate metadata column."
14
14
  s.email = "git@timothymorgan.info"
15
15
  s.extra_rdoc_files = [
@@ -25,14 +25,14 @@ Gem::Specification.new do |s|
25
25
  s.licenses = ["MIT"]
26
26
  s.require_paths = ["lib"]
27
27
  s.required_ruby_version = Gem::Requirement.new(">= 1.9")
28
- s.rubygems_version = "1.8.24"
28
+ s.rubygems_version = "1.8.25"
29
29
  s.summary = "Schemaless metadata using JSON columns"
30
30
 
31
31
  if s.respond_to? :specification_version then
32
32
  s.specification_version = 3
33
33
 
34
34
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
35
- s.add_runtime_dependency(%q<rails>, [">= 3.0"])
35
+ s.add_runtime_dependency(%q<rails>, [">= 4.0"])
36
36
  s.add_runtime_dependency(%q<boolean>, [">= 0"])
37
37
  s.add_development_dependency(%q<rspec>, [">= 0"])
38
38
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency(%q<redcarpet>, [">= 0"])
41
41
  s.add_development_dependency(%q<jeweler>, [">= 0"])
42
42
  else
43
- s.add_dependency(%q<rails>, [">= 3.0"])
43
+ s.add_dependency(%q<rails>, [">= 4.0"])
44
44
  s.add_dependency(%q<boolean>, [">= 0"])
45
45
  s.add_dependency(%q<rspec>, [">= 0"])
46
46
  s.add_dependency(%q<sqlite3>, [">= 0"])
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  s.add_dependency(%q<jeweler>, [">= 0"])
50
50
  end
51
51
  else
52
- s.add_dependency(%q<rails>, [">= 3.0"])
52
+ s.add_dependency(%q<rails>, [">= 4.0"])
53
53
  s.add_dependency(%q<boolean>, [">= 0"])
54
54
  s.add_dependency(%q<rspec>, [">= 0"])
55
55
  s.add_dependency(%q<sqlite3>, [">= 0"])
@@ -20,7 +20,7 @@ module HasMetadataColumn
20
20
  extend ActiveSupport::Concern
21
21
 
22
22
  # Valid values for the `:type` option.
23
- TYPES = [ String, Fixnum, Integer, Float, Hash, Array, TrueClass, FalseClass, Boolean, NilClass, Date, Time ]
23
+ TYPES = [String, Fixnum, Integer, Float, Hash, Array, TrueClass, FalseClass, Boolean, NilClass, Date, Time]
24
24
 
25
25
  # @private
26
26
  def self.metadata_typecast(value, type=nil)
@@ -110,7 +110,6 @@ module HasMetadataColumn
110
110
  alias_method_chain :attribute_method?, :metadata
111
111
  alias_method_chain :attribute, :metadata
112
112
  alias_method_chain :attribute_before_type_cast, :metadata
113
- alias_method_chain :_attribute, :metadata
114
113
  alias_method_chain :attribute=, :metadata
115
114
  alias_method_chain :query_attribute, :metadata
116
115
  alias_method_chain :reload, :metadata
@@ -130,31 +129,35 @@ module HasMetadataColumn
130
129
 
131
130
  validate do |obj|
132
131
  value = obj.send(name)
133
- errors.add(name, :incorrect_type) if !HasMetadataColumn.metadata_typecast(value, type).kind_of?(type) &&
134
- (!options[:allow_nil] || (options[:allow_nil] && !value.nil?)) &&
135
- (!options[:allow_blank] || (options[:allow_blank] && !value.blank?))
132
+ if !HasMetadataColumn.metadata_typecast(value, type).kind_of?(type) &&
133
+ (!options[:allow_nil] || (options[:allow_nil] && !value.nil?)) &&
134
+ (!options[:allow_blank] || (options[:allow_blank] && !value.blank?))
135
+ errors.add(name, :incorrect_type)
136
+ end
136
137
  end if type && type_validate
137
138
  validates(name, options) unless options.empty? or (options.keys - [:allow_nil, :allow_blank]).empty?
138
139
  end
139
140
  end
140
141
 
141
142
  if !respond_to?(:define_attribute_methods_with_metadata) && !superclass.respond_to?(:define_attribute_methods_with_metadata) &&
142
- !respond_to?(:define_method_attribute_with_metadata) && !superclass.respond_to?(:define_method_attribute_with_metadata)
143
+ !respond_to?(:define_method_attribute_with_metadata) && !superclass.respond_to?(:define_method_attribute_with_metadata)
143
144
  class << self
144
145
  def define_attribute_methods_with_metadata
145
146
  define_attribute_methods_without_metadata
146
147
  metadata_column_fields.keys.each { |field| define_attribute_method field }
147
148
  end
149
+
148
150
  alias_method_chain :define_attribute_methods, :metadata
149
151
 
150
152
  def define_method_attribute_with_metadata(attr_name)
151
153
  return define_method_attribute_without_metadata(attr_name) unless metadata_column_fields.include?(attr_name.to_sym)
152
154
  attribute_method_matchers.each do |matcher|
153
155
  method_name = matcher.method_name(attr_name)
154
- define_optimized_call generated_attribute_methods, method_name, matcher.method_missing_target, attr_name.to_s
156
+ define_proxy_call true, generated_attribute_methods, method_name, matcher.method_missing_target, attr_name.to_s
155
157
  attribute_method_matchers_cache.clear
156
158
  end
157
159
  end
160
+
158
161
  alias_method_chain :define_method_attribute, :metadata
159
162
  end
160
163
  end
@@ -163,10 +166,10 @@ module HasMetadataColumn
163
166
 
164
167
  # @private
165
168
  def as_json(options={})
166
- options ||= Hash.new # the JSON encoder can sometimes give us nil options?
167
- options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
168
- metadata = self.class.metadata_column_fields.keys
169
- metadata &= Array.wrap(options[:only]) if options[:only]
169
+ options ||= Hash.new # the JSON encoder can sometimes give us nil options?
170
+ options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
171
+ metadata = self.class.metadata_column_fields.keys
172
+ metadata &= Array.wrap(options[:only]) if options[:only]
170
173
  metadata -= Array.wrap(options[:except])
171
174
  options[:methods] = Array.wrap(options[:methods]) + metadata
172
175
  super options
@@ -174,9 +177,9 @@ module HasMetadataColumn
174
177
 
175
178
  # @private
176
179
  def to_xml(options={})
177
- options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
178
- metadata = self.class.metadata_column_fields.keys
179
- metadata &= Array.wrap(options[:only]) if options[:only]
180
+ options[:except] = Array.wrap(options[:except]) + [self.class.metadata_column]
181
+ metadata = self.class.metadata_column_fields.keys
182
+ metadata &= Array.wrap(options[:only]) if options[:only]
180
183
  metadata -= Array.wrap(options[:except])
181
184
  options[:methods] = Array.wrap(options[:methods]) + metadata
182
185
  super options
@@ -214,7 +217,7 @@ module HasMetadataColumn
214
217
 
215
218
  # @private
216
219
  def inspect
217
- "#<#{self.class.to_s} #{attributes.except(self.class.metadata_column.to_s).merge(_metadata_hash.try(:stringify_keys) || {}).map { |k, v| "#{k}: #{v.inspect}" }.join(', ')}>"
220
+ "#<#{self.class.to_s} #{attributes.except(self.class.metadata_column.to_s).merge(_metadata_hash.try!(:stringify_keys) || {}).map { |k, v| "#{k}: #{v.inspect}" }.join(', ')}>"
218
221
  end
219
222
 
220
223
  # @private
@@ -275,11 +278,9 @@ module HasMetadataColumn
275
278
  def attribute_with_metadata=(attr, value)
276
279
  return send(:attribute_without_metadata=, attr, value) unless self.class.metadata_column_fields.include?(attr.to_sym)
277
280
 
278
- options = self.class.metadata_column_fields[attr.to_sym] || {}
279
281
  attribute_will_change! attr
280
- @_metadata_hash ||= {}
281
- old = @_metadata_hash[attr.to_s]
282
- send :"#{self.class.metadata_column}=", @_metadata_hash.merge(attr.to_s => value).to_json
282
+ old = _metadata_hash[attr.to_s]
283
+ send :"#{self.class.metadata_column}=", _metadata_hash.merge(attr.to_s => value).to_json
283
284
  @_metadata_hash = nil
284
285
  @_changed_metadata[attr] = old
285
286
  value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_metadata_column
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-14 00:00:00.000000000 Z
12
+ date: 2013-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: '4.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '3.0'
29
+ version: '4.0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: boolean
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 1.8.24
160
+ rubygems_version: 1.8.25
161
161
  signing_key:
162
162
  specification_version: 3
163
163
  summary: Schemaless metadata using JSON columns