-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
29 lines (21 loc) · 1.03 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
EnsuresImmutabilityOf
=====================
There are many cases where a model attribute should not be changed once it's set. This plugin makes it dead simple.
Example
=======
class Account < ActiveRecord::Base
ensures_immutability_of :username, :email
end
account = Account.create(:username => 'jgreen')
...
account.update(:username => 'jgreen') # raises ActiveRecord::ImmutableAttributeError
Collections can all be immutable as well (thanks to Dmitry Ratnikov on #rubyonrails)
class Account < ActiveRecord::Base
has_many :infos
ensures_immutability_of :username, :email, :infos # note: this must come after the has_many declaration, otherwise
# AR will overwrite the setter
end
account = Account.create(:username => 'wmoxam')
account.infos = Info.find(:all, :conditions => ["id < ?", 3]
account.infos = Info.find(:all, :conditions => ["id > ?", 3] # raises ActiveRecord::ImmutableAttributeError
Copyright (c) 2007-2008 Wesley Moxam - Savvica Inc, released under the MIT license