Class: Ultracache::Relationships

Inherits:
Object
  • Object
show all
Defined in:
lib/ultracache/relationships.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/ultracache/relationships.rb', line 3

def klass
  @klass
end

#relationshipsObject (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

#eachObject



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

#keysObject



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