Module: StrictReadOnly::Extension::ClassMethods
- Defined in:
- lib/strict-read-only.rb
Instance Method Summary collapse
Instance Method Details
#read_only_attribute(*attributes) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/strict-read-only.rb', line 21 def read_only_attribute(*attributes) extension = Module.new = attributes. attributes.map(&:to_s).each do |name| extension.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name}=(*) if #{.fetch(:if, :persisted?)} @read_only_data ||= {} @read_only_data["#{name}"] = #{name} unless @read_only_data.key?("#{name}") end super end RUBY end prepend extension end |