Class: Fauxsql::DereferencedAttribute
- Inherits:
-
Object
- Object
- Fauxsql::DereferencedAttribute
- Defined in:
- lib/fauxsql/dereferenced_attribute.rb
Overview
DereferencedAttribute stores objects that quack like DataMapper::Resource This is the object that Fauxsql stores in the database when a DataMapper::Resource object is given. This way only the class and the primary key are stored.
Constant Summary collapse
- @@identity_map =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object (also: #hash)
-
#initialize(attribute) ⇒ DereferencedAttribute
constructor
A new instance of DereferencedAttribute.
- #resolve ⇒ Object
Constructor Details
#initialize(attribute) ⇒ DereferencedAttribute
Returns a new instance of DereferencedAttribute.
9 10 11 12 |
# File 'lib/fauxsql/dereferenced_attribute.rb', line 9 def initialize(attribute) @klass = attribute.class.to_s @lookup_key = attribute.key end |
Class Method Details
.get(attribute) ⇒ Object
23 24 25 26 |
# File 'lib/fauxsql/dereferenced_attribute.rb', line 23 def self.get(attribute) dereferenced = new(attribute) @@identity_map[dereferenced.hash] ||= dereferenced end |
.load(dump) ⇒ Object
28 29 30 |
# File 'lib/fauxsql/dereferenced_attribute.rb', line 28 def self.load(dump) Marshal.load(dump) end |
Instance Method Details
#dump ⇒ Object Also known as: hash
18 19 20 |
# File 'lib/fauxsql/dereferenced_attribute.rb', line 18 def dump Marshal.dump(self) end |
#resolve ⇒ Object
14 15 16 |
# File 'lib/fauxsql/dereferenced_attribute.rb', line 14 def resolve ActiveSupport::Inflector.constantize(@klass.to_s).get(*@lookup_key) end |