Class: ActiveShepherd::Aggregate

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shepherd/aggregate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_attributesObject (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

#modelObject (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_attributesObject



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

Returns:

  • (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_attributesObject



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_associationsObject



20
21
22
# File 'lib/active_shepherd/aggregate.rb', line 20

def traversable_associations
  associations.traversable
end

#untraversable_association_namesObject



24
25
26
# File 'lib/active_shepherd/aggregate.rb', line 24

def untraversable_association_names
  associations.untraversable.keys
end