public
Description: Rails Plugin - specify attributes within a model that can be set but not modified
Homepage: http://6brand.com
Clone URL: git://github.com/JackDanger/immutable_attributes.git
Search Repo:
allowing nils to be overwritten
Jack Danger Canty (author)
Tue Apr 29 09:30:24 -0700 2008
commit  e7686e142eafadd3fb42c9d4e0a08bbec1474e6f
tree    311dff8e7f35a411fed49bfb5f7a84065ae1e825
parent  611798732ebd560ac6c759976e9eff00dee4f168
...
10
11
12
13
 
 
 
14
15
16
...
10
11
12
 
13
14
15
16
17
18
0
@@ -10,7 +10,9 @@ module ImmutableAttributes
0
     args.each do |meth|
0
       class_eval do
0
         define_method("#{meth}=") do |value|
0
- new_record? ? write_attribute(meth, value) : raise(ActiveRecord::ImmutableAttributeError, "#{meth} is immutable!")
0
+ new_record? || read_attribute(meth).nil? ?
0
+ write_attribute(meth, value) :
0
+ raise(ActiveRecord::ImmutableAttributeError, "#{meth} is immutable!")
0
         end
0
       end
0
     end

Comments

    No one has commented yet.