Class: Fauxsql::DereferencedAttribute

Inherits:
Object
  • Object
show all
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

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

#dumpObject Also known as: hash



18
19
20
# File 'lib/fauxsql/dereferenced_attribute.rb', line 18

def dump
  Marshal.dump(self)
end

#resolveObject



14
15
16
# File 'lib/fauxsql/dereferenced_attribute.rb', line 14

def resolve
  ActiveSupport::Inflector.constantize(@klass.to_s).get(*@lookup_key)
end