Module: ValidatesImmutability::ClassMethods

Defined in:
lib/validates_immutability.rb

Instance Method Summary collapse

Instance Method Details

#immutable(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/validates_immutability.rb', line 7

def immutable(options = {})
  if options.key?(:on)
    raise ArgumentError, "Unknown option :on"
  end
  options.merge!(:on => :update)
  error_msg = options.delete(:message) || "Updates are not allowed."
  validate options do
    errors[:base] << error_msg if changed?
  end
end