Class: Crystal::Callbacks::AbstractCallback
- Defined in:
- lib/crystal/support/callbacks.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#executor ⇒ Object
Returns the value of attribute executor.
-
#terminator ⇒ Object
Returns the value of attribute terminator.
Instance Method Summary collapse
- #add_to_chain(target, inf, &the_next) ⇒ Object
- #run?(target, inf) ⇒ Boolean
- #terminate?(target, result) ⇒ Boolean
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
4 5 6 |
# File 'lib/crystal/support/callbacks.rb', line 4 def conditions @conditions end |
#executor ⇒ Object
Returns the value of attribute executor.
4 5 6 |
# File 'lib/crystal/support/callbacks.rb', line 4 def executor @executor end |
#terminator ⇒ Object
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
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
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 |