module NoBrainer::Document::Readonly::ClassMethods
Public Instance Methods
field(attr, options={})
click to toggle source
Calls superclass method
# File lib/no_brainer/document/readonly.rb, line 5 def field(attr, options={}) super inject_in_layer :readonly do case options[:readonly] when true define_method("#{attr}=") do |value| unless new_record? if read_attribute(attr) != value raise NoBrainer::Error::ReadonlyField.new("#{attr} is readonly") end end super(value) end when false then remove_method("#{attr}=") if method_defined?("#{attr}=") end end end
remove_field(attr, options={})
click to toggle source
Calls superclass method
# File lib/no_brainer/document/readonly.rb, line 23 def remove_field(attr, options={}) super inject_in_layer :readonly do remove_method("#{attr}=") if method_defined?("#{attr}=") end end