lib/dirty_attributes.rb in dirty_hashy-0.1.1 vs lib/dirty_attributes.rb in dirty_hashy-0.1.2

- old
+ new

@@ -10,26 +10,28 @@ def attrs(*names) @attrs = names.collect(&:to_s) end def attributes - @attrs || [] + @attrs end end module InstanceMethods attr_reader :attributes def initialize - attrs = self.class.attributes.inject({}){|h, a| h.merge({a => nil})} - @attributes = DirtyHashy.new(attrs).tap do |hashy| - dirty_map! hashy, attrs.keys + @attributes = DirtyHashy.new({}, true, self.class.attributes).tap do |hashy| + dirty_map! hashy clean_up! end end def attributes=(other) - attributes.clear.merge! other + attributes.replace other + rescue IndexError => e + e.message.match /"(.*)"/ + raise NoMethodError, "undefined method `#{$1}=' for #{self.inspect}" end end end \ No newline at end of file