Class: PriceHubble::BaseEntity
- Inherits:
-
Object
- Object
- PriceHubble::BaseEntity
- Extended by:
- Utils::Bangers
- Includes:
- ActiveModel::Dirty, ActiveModel::Model, EntityConcern::Associations, EntityConcern::Attributes, EntityConcern::Callbacks, EntityConcern::Client, EntityConcern::Persistence, Utils::Bangers
- Defined in:
- lib/price_hubble/entity/base_entity.rb
Overview
The base entity, with a lot of known ActiveRecord/ActiveModel features.
Direct Known Subclasses
Address, Authentication, Coordinates, Dossier, Location, Property, PropertyConditions, PropertyQualities, PropertyType, Valuation, ValuationRequest, ValuationScores
Instance Attribute Summary collapse
-
#_unmapped ⇒ Object
We collect all unknown attributes instead of raising while creating a new instance.
Class Method Summary collapse
-
.inherited(child_class) ⇒ Object
Initialize the class we were inherited to.
Instance Method Summary collapse
-
#initialize(struct = {}) {|PriceHubble::BaseEntity| ... } ⇒ PriceHubble::BaseEntity
constructor
Create a new instance of an entity with a lot of known ActiveRecord/ActiveModel features.
Methods included from Utils::Bangers
Methods included from EntityConcern::Persistence
#destroyed?, #mark_as_destroyed, #new_record?, #persisted?
Methods included from EntityConcern::Client
Methods included from EntityConcern::Associations
has_many, has_one, inherited_setup_associations
Methods included from EntityConcern::Attributes
#assign_attributes, #attributes, inherited_setup_attributes, tracked_attr, typed_attr
Methods included from EntityConcern::Attributes::StringInquirer
Methods included from EntityConcern::Attributes::Range
Methods included from EntityConcern::Attributes::Enum
Methods included from EntityConcern::Attributes::DateArray
Constructor Details
#initialize(struct = {}) {|PriceHubble::BaseEntity| ... } ⇒ PriceHubble::BaseEntity
Create a new instance of an entity with a lot of known ActiveRecord/ActiveModel features.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/price_hubble/entity/base_entity.rb', line 34 def initialize(struct = {}) # Set the initial unmapped struct self._unmapped = RecursiveOpenStruct.new # Build a RecursiveOpenStruct and a simple hash from the given data struct, hash = sanitize_data(struct) # Initialize associations and map them accordingly struct, hash = initialize_associations(struct, hash) # Initialize attributes and map unknown ones and pass back the known known = initialize_attributes(struct, hash) # Mass assign the known attributes via ActiveModel super(known) # Follow the ActiveRecord API yield self if block_given? # Run the initializer callbacks _run_initialize_callbacks end |
Instance Attribute Details
#_unmapped ⇒ Object
We collect all unknown attributes instead of raising while creating a new instance. The unknown attributes are wrapped inside a RecursiveOpenStruct
to ease the accessibility. This also allows us to handle responses in a forward-compatible way.
26 27 28 |
# File 'lib/price_hubble/entity/base_entity.rb', line 26 def _unmapped @_unmapped end |
Class Method Details
.inherited(child_class) ⇒ Object
Initialize the class we were inherited to. We trigger all our methods which start with inherited_setup_
to allow per-concern/feature based initialization after BaseEntity inheritance.
57 58 59 60 61 62 |
# File 'lib/price_hubble/entity/base_entity.rb', line 57 def inherited(child_class) super match = ->(sym) { sym.to_s.start_with? 'inherited_setup_' } trigger = ->(sym) { send(sym, child_class) } methods.select(&match).each(&trigger) end |