has_metadata 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  h1. has_metadata -- Keep your tables narrow
2
2
 
3
3
  | *Author* | Tim Morgan |
4
- | *Version* | 1.5.3 (Jan 23, 2012) |
4
+ | *Version* | 1.5.4 (Jan 24, 2012) |
5
5
  | *License* | Released under the MIT License. |
6
6
 
7
7
  h2. Important note for those upgrading from 1.0 to 1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "has_metadata"
8
- s.version = "1.5.2"
8
+ s.version = "1.5.4"
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-01-24"
12
+ s.date = "2012-01-25"
13
13
  s.description = "has_metadata lets you move non-indexed and weighty columns off of your big tables by creating a separate metadata table to store all this extra information. Works with Ruby 1.9. and Rails 3.0."
14
14
  s.email = "git@timothymorgan.info"
15
15
  s.extra_rdoc_files = [
@@ -73,6 +73,9 @@ module HasMetadata
73
73
 
74
74
  define_method(:save_metadata) { metadata.save! }
75
75
  define_method(:metadata_changed?) { metadata.try :changed? }
76
+
77
+ alias_method_chain :changed_attributes, :metadata
78
+ alias_method_chain :attribute_will_change!, :metadata
76
79
  else
77
80
  raise "Cannot redefine existing metadata fields: #{(fields.keys & self.metadata_fields.keys).to_sentence}" unless (fields.keys & self.metadata_fields.keys).empty?
78
81
  self.metadata_fields = self.metadata_fields.merge(fields)
@@ -146,7 +149,7 @@ module HasMetadata
146
149
  # saved one if none was found.
147
150
 
148
151
  def metadata!
149
- if instance_variables.include?(:@metadata) then
152
+ if instance_variables.include?(:@metadata) && metadata then
150
153
  metadata
151
154
  else
152
155
  if new_record? then
@@ -162,4 +165,18 @@ module HasMetadata
162
165
  "#<#{self.class.to_s} #{attributes.merge(metadata.try(:data).try(:stringify_keys) || {}).map { |k,v| "#{k}: #{v.inspect}" }.join(', ')}>"
163
166
  end
164
167
  end
168
+
169
+ # @private
170
+ def changed_attributes_with_metadata
171
+ changed_attributes_without_metadata.merge(metadata.try(:changed_metadata) || {})
172
+ end
173
+
174
+ # @private
175
+ def attribute_will_change_with_metadata!(attr)
176
+ if attribute_names.include?(attr) then
177
+ attribute_will_change_without_metadata! attr
178
+ else
179
+ metadata!.send :attribute_will_change!, attr
180
+ end
181
+ end
165
182
  end
@@ -56,12 +56,19 @@ module HasMetadata
56
56
 
57
57
  options = fields[name] || {}
58
58
  data_will_change!
59
+ attribute_will_change! name.to_s
59
60
  data[name] = HasMetadata.metadata_typecast(value, options[:type])
60
61
  end
61
62
 
62
63
  self
63
64
  end
64
65
 
66
+ # @return [Hash<String, Object>] A hash of metadata fields that have been
67
+ # altered.
68
+ def changed_metadata
69
+ changed_attributes.except(*attribute_names)
70
+ end
71
+
65
72
  private
66
73
 
67
74
  def initialize_data
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70238498869260 !ruby/object:Gem::Requirement
16
+ requirement: &70232408519820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - <
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70238498869260
24
+ version_requirements: *70232408519820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: boolean
27
- requirement: &70238498722520 !ruby/object:Gem::Requirement
27
+ requirement: &70232408526660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70238498722520
35
+ version_requirements: *70232408526660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70238498878240 !ruby/object:Gem::Requirement
38
+ requirement: &70232412633380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70238498878240
46
+ version_requirements: *70232412633380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard
49
- requirement: &70238498887960 !ruby/object:Gem::Requirement
49
+ requirement: &70232412641340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70238498887960
57
+ version_requirements: *70232412641340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: RedCloth
60
- requirement: &70238498966980 !ruby/object:Gem::Requirement
60
+ requirement: &70232412651340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70238498966980
68
+ version_requirements: *70232412651340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &70238498988960 !ruby/object:Gem::Requirement
71
+ requirement: &70232412659240 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70238498988960
79
+ version_requirements: *70232412659240
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70238499053380 !ruby/object:Gem::Requirement
82
+ requirement: &70232412546900 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70238499053380
90
+ version_requirements: *70232412546900
91
91
  description: has_metadata lets you move non-indexed and weighty columns off of your
92
92
  big tables by creating a separate metadata table to store all this extra information.
93
93
  Works with Ruby 1.9. and Rails 3.0.