Module: PhModel

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Includes:
ActiveAttr::AttributeDefaults, ActiveAttr::BasicModel, ActiveAttr::MassAssignment, ActiveAttr::QueryAttributes, Concerns::ValidatedFactory
Defined in:
lib/ph_model.rb,
lib/ph_model/version.rb,
lib/ph_model/concerns.rb,
lib/ph_model/validation_failed.rb,
lib/ph_model/concerns/validated_factory.rb

Overview

PayrollHero's mashup of ActiveModel and ActiveAttr with some of our own twists

Defined Under Namespace

Modules: Concerns Classes: ValidationFailed

Constant Summary collapse

VERSION =
'0.0.1'.freeze

Instance Method Summary collapse

Instance Method Details

#assign_attributes(new_attributes, options = {}) ⇒ Object

Monkey patch #assign_attributes inside ActiveAttr::MassAssignment so that it doesn't blindly ignore attempting to assign attributes which do not exist

TODO: try to submit something upstream to deal with this



30
31
32
33
34
35
36
37
38
39
# File 'lib/ph_model.rb', line 30

def assign_attributes(new_attributes, options = {})
  sanitized_new_attributes = sanitize_for_mass_assignment_if_sanitizer new_attributes, options

  sanitized_new_attributes.each do |name, value|
    writer = "#{name}="
    # originally:
    # send writer, value if respond_to? writer
    send writer, value
  end if sanitized_new_attributes
end