Class: Fauxsql::AttributeMap
- Inherits:
-
Hash
- Object
- Hash
- Fauxsql::AttributeMap
- Defined in:
- lib/fauxsql/attribute_map.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
We dereference and resolve the key because in Ruby not any object can be a hash key.
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
-
#eql?(other) ⇒ Boolean
Always being not eql is expensive TODO make this work without this hack.
-
#keys ⇒ Object
VERY VERY SPECIFIC to the marshal dump format.
- #resolve_key(key) ⇒ Object
- #resolve_value(value) ⇒ Object
Instance Method Details
#[](key) ⇒ Object
21 22 23 24 |
# File 'lib/fauxsql/attribute_map.rb', line 21 def [] key real_key = Fauxsql.dereference_fauxsql_key(key) Fauxsql.resolve_fauxsql_attribute super(real_key) end |
#[]=(key, value) ⇒ Object
We dereference and resolve the key because in Ruby not any object can be a hash key. Even a DataMapper record.
15 16 17 18 19 |
# File 'lib/fauxsql/attribute_map.rb', line 15 def []= key, value real_key = Fauxsql.dereference_fauxsql_key(key) real_value = Fauxsql.dereference_fauxsql_attribute(value) super real_key, real_value end |
#delete(key) ⇒ Object
26 27 28 29 |
# File 'lib/fauxsql/attribute_map.rb', line 26 def delete key real_key = Fauxsql.dereference_fauxsql_key(key) super(real_key) end |
#each(&block) ⇒ Object
31 32 33 34 35 |
# File 'lib/fauxsql/attribute_map.rb', line 31 def each(&block) super do |key, value| yield(resolve_key(key), resolve_value(value)) end end |
#eql?(other) ⇒ Boolean
Always being not eql is expensive TODO make this work without this hack
59 60 61 |
# File 'lib/fauxsql/attribute_map.rb', line 59 def eql?(other) return false end |
#keys ⇒ Object
VERY VERY SPECIFIC to the marshal dump format. Probably brittle.
39 40 41 42 43 |
# File 'lib/fauxsql/attribute_map.rb', line 39 def keys super.map do |key| resolve_key(key) end end |
#resolve_key(key) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/fauxsql/attribute_map.rb', line 45 def resolve_key(key) if key.respond_to?(:match) && key.match(/^.+Fauxsql::DereferencedAttribute.+@lookup_key.+$/) Fauxsql.resolve_fauxsql_attribute Fauxsql::DereferencedAttribute.load(key) else key end end |
#resolve_value(value) ⇒ Object
53 54 55 |
# File 'lib/fauxsql/attribute_map.rb', line 53 def resolve_value(value) Fauxsql.resolve_fauxsql_attribute value end |