module Fakecrm::TolerantMassAssignment
Public Instance Methods
attributes=(attributes)
click to toggle source
Assign values to multiple attributes in one call (mass assignment)
@param [Hash] attributes
names and values of attributes to assign
@return [Hash]
names and values of attributes assigned
@note unknown custom_* attributes are ignored with warning
@api public
# File lib/fakecrm/tolerant_mass_assignment.rb, line 14 def attributes=(attributes) model = self.model attributes.each do |name, value| case name when String, Symbol if model.allowed_writer_methods.include?(setter = "#{name}=") __send__(setter, value) else if name.to_s =~ /^custom_/ ::Fakecrm.logger.error("Ignoring the unknown attribute '#{name}' in #{model}") else raise ArgumentError, "The attribute '#{name}' is not accessible in #{model}" end end when Associations::Relationship, Property # only call a public #typecast (e.g. on Property instances) if name.respond_to?(:typecast) value = name.typecast(value) end self.persistence_state = persistence_state.set(name, value) end end end