Class: JsonapiCompliable::Util::Hooks

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi_compliable/util/hooks.rb

Class Method Summary collapse

Class Method Details

.add(prc) ⇒ Object

Because hooks will be added from the outer edges of the graph, working inwards



24
25
26
# File 'lib/jsonapi_compliable/util/hooks.rb', line 24

def self.add(prc)
  _hooks.unshift(prc)
end

.hooks=(val) ⇒ Object



18
19
20
# File 'lib/jsonapi_compliable/util/hooks.rb', line 18

def self.hooks=(val)
  Thread.current[:_compliable_hooks] = val
end

.recordObject



4
5
6
7
8
9
10
11
# File 'lib/jsonapi_compliable/util/hooks.rb', line 4

def self.record
  self.hooks = []
  begin
    yield.tap { run }
  ensure
    self.hooks = []
  end
end

.runObject



28
29
30
# File 'lib/jsonapi_compliable/util/hooks.rb', line 28

def self.run
  _hooks.each { |h| h.call }
end