module PhModel

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

Constants

VERSION

Public Instance Methods

as_json(*) click to toggle source
# File lib/ph_model.rb, line 34
def as_json(*)
  {}.tap do |hash|
    self.class.attributes.each do |attribute_name, _info|
      hash[attribute_name] = send(attribute_name).as_json
    end
  end
end
assign_attributes(new_attributes, options = {}) click to toggle source

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

# File lib/ph_model.rb, line 52
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
inspect() click to toggle source
# File lib/ph_model.rb, line 42
def inspect
  attr_info = self.class.attributes.map { |attr_name, info| "#{attr_name}: #{self.send(attr_name).inspect}" }.join(", ")
  "#<#{self.model_name} #{attr_info}>"
end