module StrictReadOnly::Extension::ClassMethods
Public Instance Methods
read_only_attribute(*attributes)
click to toggle source
# File lib/strict-read-only.rb, line 21 def read_only_attribute(*attributes) extension = Module.new options = attributes.extract_options! attributes.map(&:to_s).each do |name| extension.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name}=(*) if #{options.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