Class: Rad::Callbacks::AbstractCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/rad/support/callbacks.rb

Direct Known Subclasses

AfterCallback, AroundCallback, BeforeCallback

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



5
6
7
# File 'lib/rad/support/callbacks.rb', line 5

def conditions
  @conditions
end

#executorObject

Returns the value of attribute executor.



4
5
6
# File 'lib/rad/support/callbacks.rb', line 4

def executor
  @executor
end

#terminatorObject

Returns the value of attribute terminator.



4
5
6
# File 'lib/rad/support/callbacks.rb', line 4

def terminator
  @terminator
end

Instance Method Details

#add_to_chain(target, inf, &the_next) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/rad/support/callbacks.rb', line 46

def add_to_chain target, inf, &the_next
  if run? target, inf
    build_block target, &the_next
  else
    the_next
  end         
end

#run?(target, inf) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rad/support/callbacks.rb', line 32

def run? target, inf
  if cond = conditions[:if]
    evaluate_if(cond, target, inf)
  elsif cond = conditions[:unless]
    !evaluate_if(cond, target, inf)
  elsif cond = conditions[:only]
    evaluate_only(cond, inf)
  elsif cond = conditions[:except]
    !evaluate_only(cond, inf)
  else
    true
  end
end

#terminate?(target, result) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rad/support/callbacks.rb', line 20

def terminate? target, result
  unless terminator.nil?
    if terminator.is_a? Proc
      terminator.call target, result
    else
      result == terminator
    end
  else
    false
  end
end