Class: Persistence::Object::Complex::Attributes::HashToPort

Inherits:
Hash
  • Object
show all
Defined in:
lib/persistence/object/complex/attributes/hash_to_port.rb

Overview

Hash subclass used for encapsulating common process of translation from Ruby key/value to storage key/value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#persistence_objectObject

Returns the value of attribute persistence_object.



9
10
11
# File 'lib/persistence/object/complex/attributes/hash_to_port.rb', line 9

def persistence_object
  @persistence_object
end

Instance Method Details

#[]=(key, value) ⇒ Object

Automatically convert key/value to primary key/storage value.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/persistence/object/complex/attributes/hash_to_port.rb', line 21

def []=( key, value )

  primary_key = nil
  attribute_value_to_port = nil
  
  # if we don't have a persistence port we want to compare objects by their properties
  if persistence_object.persistence_port
    attribute_key_to_port   = persistence_object.persist_as_sub_object_or_attribute_and_return_id_or_value( key )
    primary_key             = persistence_object.persistence_bucket.primary_key_for_attribute_name( persistence_object, attribute_key_to_port )
    attribute_value_to_port = persistence_object.persist_as_sub_object_or_attribute_and_return_id_or_value( value )
  else
    primary_key             = key
    attribute_value_to_port = value
  end
  
  super( primary_key, attribute_value_to_port )

end