Class: ActiveFacts::API::InstanceIndex

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/activefacts/api/instance_index.rb

Overview

Each Constellation maintains an InstanceIndex for each ObjectType in its Vocabulary. The InstanceIndex object is returned when you call @constellation.ObjectType with no arguments (where ObjectType is the object_type name you’re interested in)

Instance Method Summary collapse

Constructor Details

#initialize(constellation, klass) ⇒ InstanceIndex

Returns a new instance of InstanceIndex.



22
23
24
25
26
# File 'lib/activefacts/api/instance_index.rb', line 22

def initialize(constellation, klass)
  @constellation = constellation
  @klass = klass
  @hash = {}
end

Instance Method Details

#[](key) ⇒ Object



41
42
43
# File 'lib/activefacts/api/instance_index.rb', line 41

def [](key)
  @hash[flatten_key(key)]
end

#[]=(key, value) ⇒ Object

:nodoc:



37
38
39
# File 'lib/activefacts/api/instance_index.rb', line 37

def []=(key, value)   #:nodoc:
  @hash[flatten_key(key)] = value
end

#detect(&b) ⇒ Object



32
33
34
35
# File 'lib/activefacts/api/instance_index.rb', line 32

def detect &b
  r = @hash.detect &b
  r ? r[1] : nil
end

#inspectObject



28
29
30
# File 'lib/activefacts/api/instance_index.rb', line 28

def inspect
  "<InstanceIndex for #{@klass.name} in #{@constellation.inspect}>"
end

#refresh_key(key) ⇒ Object



45
46
47
48
# File 'lib/activefacts/api/instance_index.rb', line 45

def refresh_key(key)
  value = @hash.delete(key)
  @hash[value.identifying_role_values] = value if value
end