Class: ActiveShepherd::Aggregate
- Inherits:
-
Object
- Object
- ActiveShepherd::Aggregate
- Defined in:
- lib/active_shepherd/aggregate.rb
Instance Attribute Summary collapse
-
#excluded_attributes ⇒ Object
readonly
Returns the value of attribute excluded_attributes.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #default_attributes ⇒ Object
- #deserialize_value(attribute_name, value) ⇒ Object
- #in_namespace?(name) ⇒ Boolean
-
#initialize(model, excluded_attributes = []) ⇒ Aggregate
constructor
A new instance of Aggregate.
- #raw_attributes ⇒ Object
- #serialize_value(attribute_name, value) ⇒ Object
- #traversable_associations ⇒ Object
- #untraversable_association_names ⇒ Object
Constructor Details
#initialize(model, excluded_attributes = []) ⇒ Aggregate
Returns a new instance of Aggregate.
5 6 7 8 9 10 |
# File 'lib/active_shepherd/aggregate.rb', line 5 def initialize(model, excluded_attributes = []) @model = model @excluded_attributes = ["id", "created_at", "updated_at"] @excluded_attributes.concat(Array.wrap(excluded_attributes).map(&:to_s)) end |
Instance Attribute Details
#excluded_attributes ⇒ Object (readonly)
Returns the value of attribute excluded_attributes.
2 3 4 |
# File 'lib/active_shepherd/aggregate.rb', line 2 def excluded_attributes @excluded_attributes end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/active_shepherd/aggregate.rb', line 3 def model @model end |
Instance Method Details
#default_attributes ⇒ Object
12 13 14 |
# File 'lib/active_shepherd/aggregate.rb', line 12 def default_attributes model.class.new.attributes end |
#deserialize_value(attribute_name, value) ⇒ Object
32 33 34 |
# File 'lib/active_shepherd/aggregate.rb', line 32 def deserialize_value(attribute_name, value) run_through_serializer(attribute_name, value, :load) end |
#in_namespace?(name) ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_shepherd/aggregate.rb', line 36 def in_namespace?(name) my_namespace = model.class.to_s if name == my_namespace false elsif name.deconstantize == my_namespace true elsif name.deconstantize == my_namespace.deconstantize && !name.deconstantize.blank? true else false end end |
#raw_attributes ⇒ Object
16 17 18 |
# File 'lib/active_shepherd/aggregate.rb', line 16 def raw_attributes model.attributes_before_type_cast end |
#serialize_value(attribute_name, value) ⇒ Object
28 29 30 |
# File 'lib/active_shepherd/aggregate.rb', line 28 def serialize_value(attribute_name, value) run_through_serializer(attribute_name, value, :dump) end |
#traversable_associations ⇒ Object
20 21 22 |
# File 'lib/active_shepherd/aggregate.rb', line 20 def traversable_associations associations.traversable end |
#untraversable_association_names ⇒ Object
24 25 26 |
# File 'lib/active_shepherd/aggregate.rb', line 24 def untraversable_association_names associations.untraversable.keys end |