Skip to content

Latest commit

 

History

History
146 lines (60 loc) · 1.99 KB

Property.rst

File metadata and controls

146 lines (60 loc) · 1.99 KB

Property

Property/UndefinedPropertyError

Property/MultiparameterAssignmentError

Property/ClassMethods

Constants

Files

Methods

#[]

Returning nil when we get ActiveAttr::UnknownAttributeError from ActiveAttr

ruby

def read_attribute(name)

super(name)

rescue ActiveAttr::UnknownAttributeError

nil

end

#_persisted_obj

Returns the value of attribute _persisted_obj

ruby

def _persisted_obj

@_persisted_obj

end

#initialize

TODO: Remove the commented :super entirely once this code is part of a release. It calls an init method in active_attr that has a very negative impact on performance.

ruby

def initialize(attributes = nil)

attributes = process_attributes(attributes) @relationship_props = self.class.extract_association_attributes!(attributes) writer_method_props = extract_writer_methods!(attributes) validate_attributes!(attributes) send_props(writer_method_props)

@_persisted_obj = nil

end

#read_attribute

Returning nil when we get ActiveAttr::UnknownAttributeError from ActiveAttr

ruby

def read_attribute(name)

super(name)

rescue ActiveAttr::UnknownAttributeError

nil

end

#send_props

ruby

def send_props(hash)

return hash if hash.blank? hash.each { self.send("#{key}=", value) }

end