Class: Ultracache::Relationships
- Inherits:
-
Object
- Object
- Ultracache::Relationships
- Defined in:
- lib/ultracache/relationships.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
Instance Method Summary collapse
- #add(relationship) ⇒ Object
- #each ⇒ Object
- #find(name) ⇒ Object (also: #[])
-
#initialize(klass, rs = {}) ⇒ Relationships
constructor
A new instance of Relationships.
- #keys ⇒ Object
- #merge(another) ⇒ Object (also: #|)
Constructor Details
#initialize(klass, rs = {}) ⇒ Relationships
Returns a new instance of Relationships.
6 7 8 9 |
# File 'lib/ultracache/relationships.rb', line 6 def initialize(klass, rs = {}) @relationships = rs @klass = klass end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/ultracache/relationships.rb', line 3 def klass @klass end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
4 5 6 |
# File 'lib/ultracache/relationships.rb', line 4 def relationships @relationships end |
Instance Method Details
#add(relationship) ⇒ Object
11 12 13 |
# File 'lib/ultracache/relationships.rb', line 11 def add(relationship) @relationships[relationship.name] = relationship end |
#each ⇒ Object
24 25 26 27 28 |
# File 'lib/ultracache/relationships.rb', line 24 def each @relationships.each do |k,v| yield k, v end end |
#find(name) ⇒ Object Also known as: []
19 20 21 |
# File 'lib/ultracache/relationships.rb', line 19 def find(name) @relationships[name] end |
#keys ⇒ Object
15 16 17 |
# File 'lib/ultracache/relationships.rb', line 15 def keys @relationships.keys end |
#merge(another) ⇒ Object Also known as: |
30 31 32 33 34 35 36 37 38 |
# File 'lib/ultracache/relationships.rb', line 30 def merge(another) klass = if another.klass >= @klass @klass else another.klass end Relationships.new(klass, @relationships.merge(another.relationships)) end |