Class: ActiveFacts::API::InstanceIndex
- 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 Attribute Summary collapse
-
#sort ⇒ Object
readonly
Returns the value of attribute sort.
Class Method Summary collapse
-
.def_single_delegator(accessor, method, *expected_arities) ⇒ Object
Should be in module ForwardableWithArityChecking.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
:nodoc:.
- #delete(k) ⇒ Object
- #detect(&b) ⇒ Object
- #form_key(key) ⇒ Object
-
#initialize(constellation, klass, sort) ⇒ InstanceIndex
constructor
A new instance of InstanceIndex.
- #inspect ⇒ Object
- #refresh_key(old_key) ⇒ Object
Constructor Details
#initialize(constellation, klass, sort) ⇒ InstanceIndex
Returns a new instance of InstanceIndex.
82 83 84 85 86 87 |
# File 'lib/activefacts/api/instance_index.rb', line 82 def initialize(constellation, klass, sort) @constellation = constellation @klass = klass @sort = sort @hash = sort ? RBTree.new : {} end |
Instance Attribute Details
#sort ⇒ Object (readonly)
Returns the value of attribute sort.
59 60 61 |
# File 'lib/activefacts/api/instance_index.rb', line 59 def sort @sort end |
Class Method Details
.def_single_delegator(accessor, method, *expected_arities) ⇒ Object
Should be in module ForwardableWithArityChecking
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/activefacts/api/instance_index.rb', line 62 def self.def_single_delegator(accessor, method, *expected_arities) str = %{ def #{method}(*args, &block) if #{expected_arities.size == 0 ? "block" : "!block || !#{expected_arities.inspect}.include?(block.arity)" } raise ArgumentError.new("Arity mismatch on #{name}\##{method}, got \#{block ? block.arity : 'none'} want #{expected_arities.inspect} at \#{caller*"\n\t"})") end #{accessor}.__send__(:#{method}, *args, &block) end } eval(str) end |
Instance Method Details
#[](key) ⇒ Object
106 107 108 |
# File 'lib/activefacts/api/instance_index.rb', line 106 def [](key) @hash[@sort ? form_key(key) : key] end |
#[]=(key, value) ⇒ Object
:nodoc:
102 103 104 |
# File 'lib/activefacts/api/instance_index.rb', line 102 def []=(key, value) #:nodoc: @hash[@sort ? form_key(key) : key] = value end |
#delete(k) ⇒ Object
93 94 95 |
# File 'lib/activefacts/api/instance_index.rb', line 93 def delete(k) @hash.delete(@sort ? form_key(k) : k) end |
#detect(&b) ⇒ Object
97 98 99 100 |
# File 'lib/activefacts/api/instance_index.rb', line 97 def detect &b r = @hash.detect &b r ? r[1] : nil end |
#form_key(key) ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/activefacts/api/instance_index.rb', line 116 def form_key key case key when Array KeyArray.new(key) when nil [] else key end end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/activefacts/api/instance_index.rb', line 89 def inspect "<InstanceIndex for #{@klass.name} in #{@constellation.inspect}>" end |
#refresh_key(old_key) ⇒ Object
110 111 112 113 114 |
# File 'lib/activefacts/api/instance_index.rb', line 110 def refresh_key(old_key) value = @hash.delete(@sort ? form_key(old_key) : old_key) new_key = value.(@klass) @hash[@sort ? form_key(new_key) : new_key] = value if value end |