Method: Sohm::Model.serial_attribute
- Defined in:
- lib/sohm.rb
.serial_attribute(name, cast = nil) ⇒ Object
Attributes that require CAS property
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/sohm.rb', line 834 def self.serial_attribute(name, cast = nil) if attributes.include?(name) raise ArgumentError, "#{name} is already used as a normal attribute." end serial_attributes << name unless serial_attributes.include?(name) if cast define_method(name) do # NOTE: This is a temporary solution, since we might use # composite objects (such as arrays), which won't always # do a reset @serial_attributes_changed = true cast[@serial_attributes[name]] end else define_method(name) do @serial_attributes_changed = true @serial_attributes[name] end end define_method(:"#{name}=") do |value| @serial_attributes_changed = true @serial_attributes[name] = value end end |