meta_content 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/meta_content.rb CHANGED
@@ -74,7 +74,7 @@ module MetaContent
74
74
  namespaced_is.each do |k,v|
75
75
  if v == nil
76
76
  deletes[namespace] << k
77
- elsif was[k] != v
77
+ elsif namespaced_was[k] != v
78
78
  updates[namespace][k] = v
79
79
  end
80
80
  end
@@ -107,14 +107,28 @@ module MetaContent
107
107
  end
108
108
 
109
109
  def write_meta(namespace, field, value)
110
- self.meta[namespace] ||= {}
110
+ # we want to leverage changes, but nested hashes are a problem because it's not a deep clone
111
+ cached_original = nil
112
+ setting_original = !changed_attributes.include?(:meta)
113
+
114
+ if !self.meta[namespace]
115
+ # save it before we mess with it
116
+ cached_original ||= self.meta.deep_dup if setting_original
117
+ self.meta[namespace] = {}
118
+ end
111
119
  unless self.meta[namespace][field] == value
112
120
  attribute_name = namespace.to_s == 'class' ? field : [namespace, field].join('_')
113
121
  attribute_will_change!(attribute_name)
114
- attribute_will_change!(:meta)
122
+
123
+ cached_original ||= self.meta.deep_dup if setting_original
115
124
 
116
125
  type = field_meta(namespace, field)[:type]
117
- self.meta[namespace][field] = meta_sanitizer.sanitize(value, type || :string)
126
+ val = self.meta[namespace][field] = meta_sanitizer.sanitize(value, type || :string)
127
+
128
+ # same as attribute_will_change but with a deep dup include of a shallow clone
129
+ changed_attributes[:meta] = cached_original if setting_original
130
+
131
+ val
118
132
  end
119
133
  end
120
134
 
@@ -1,3 +1,3 @@
1
1
  module MetaContent
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-08 00:00:00.000000000 Z
13
+ date: 2013-05-10 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Store your data in a key/value table in MySQL
16
16
  email:
@@ -56,4 +56,3 @@ signing_key:
56
56
  specification_version: 3
57
57
  summary: Store your data in a key/value table in MySQL
58
58
  test_files: []
59
- has_rdoc: