Class: Phenomenal::RelationshipStore
- Inherits:
-
Object
- Object
- Phenomenal::RelationshipStore
- Defined in:
- lib/phenomenal/relationship/relationship_store.rb
Overview
Define the class where all the actives relationships are efficiently stored
Instance Attribute Summary collapse
-
#sources ⇒ Object
Returns the value of attribute sources.
-
#targets ⇒ Object
Returns the value of attribute targets.
Instance Method Summary collapse
- #add(relationship) ⇒ Object
-
#get_for(context) ⇒ Object
Return all relationships for ‘context’.
- #include?(relationship) ⇒ Boolean
-
#initialize ⇒ RelationshipStore
constructor
A new instance of RelationshipStore.
- #remove(relationship) ⇒ Object
- #update_references(context) ⇒ Object
Constructor Details
#initialize ⇒ RelationshipStore
Returns a new instance of RelationshipStore.
6 7 8 9 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 6 def initialize @sources = {} @targets = {} end |
Instance Attribute Details
#sources ⇒ Object
Returns the value of attribute sources.
4 5 6 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 4 def sources @sources end |
#targets ⇒ Object
Returns the value of attribute targets.
4 5 6 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 4 def targets @targets end |
Instance Method Details
#add(relationship) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 11 def add(relationship) if @sources[relationship.source].nil? @sources[relationship.source] = Array.new end @sources[relationship.source].push(relationship) if @targets[relationship.target].nil? @targets[relationship.target] = Array.new end @targets[relationship.target].push(relationship) end |
#get_for(context) ⇒ Object
Return all relationships for ‘context’
50 51 52 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 50 def get_for(context) array_for(@sources,context).concat(array_for(@targets,context)) end |
#include?(relationship) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 28 def include?(relationship) if @sources[relationship.source] @sources[relationship.source].include?(relationship) else false end end |
#remove(relationship) ⇒ Object
23 24 25 26 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 23 def remove(relationship) @sources[relationship.source].delete(relationship) if @sources[relationship.source] # In case of rollback @targets[relationship.target].delete(relationship) if @targets[relationship.target] end |
#update_references(context) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/phenomenal/relationship/relationship_store.rb', line 36 def update_references(context) # Do nothing when anonymous, references are already valid return if context.anonymous? # Update sources set_references(@sources,context) do relationship.source=context end # Update targets set_references(@sources,context) do relationship.target=context end end |