Class: Siren::Reference

Inherits:
Object
  • Object
show all
Includes:
Eventful
Defined in:
lib/siren/reference.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Reference

Returns a new instance of Reference.



14
15
16
17
18
# File 'lib/siren/reference.rb', line 14

def initialize(hash)
  @query = Siren.compile_query(hash[REF_FIELD])
  @@cache ||= {}
  @@cache[hash.__id__] = self
end

Class Method Details

.flush!Object



6
7
8
# File 'lib/siren/reference.rb', line 6

def self.flush!
  @@cache = {}
end

.resolve!(root, symbols) ⇒ Object



10
11
12
# File 'lib/siren/reference.rb', line 10

def self.resolve!(root, symbols)
  @@cache.each { |id, ref| ref.resolve!(root, symbols) }
end

Instance Method Details

#find(root, symbols, current) ⇒ Object



24
25
26
# File 'lib/siren/reference.rb', line 24

def find(root, symbols, current)
  @query.value(root, symbols, current)
end

#resolve!(root, symbols) ⇒ Object



20
21
22
# File 'lib/siren/reference.rb', line 20

def resolve!(root, symbols)
  fire(:resolve, root, symbols)
end