Class: Crystal::Callbacks::AbstractCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/crystal/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.



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

def conditions
  @conditions
end

#executorObject

Returns the value of attribute executor.



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

def executor
  @executor
end

#terminatorObject

Returns the value of attribute terminator.



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

def terminator
  @terminator
end

Instance Method Details

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



32
33
34
35
36
37
38
# File 'lib/crystal/support/callbacks.rb', line 32

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)


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

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)


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/crystal/support/callbacks.rb', line 6

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