module CallableTree::Node::Hooks::Call
Attributes
after_callbacks[W]
around_callbacks[W]
before_callbacks[W]
Public Class Methods
included(_subclass)
click to toggle source
# File lib/callable_tree/node/hooks/call.rb, line 7 def self.included(_subclass) raise ::CallableTree::Error, "#{self} must be prepended" end
Public Instance Methods
after_call(&block)
click to toggle source
# File lib/callable_tree/node/hooks/call.rb, line 21 def after_call(&block) after_callbacks << block self end
after_callbacks()
click to toggle source
# File lib/callable_tree/node/hooks/call.rb, line 50 def after_callbacks @after_callbacks ||= [] end
around_call(&block)
click to toggle source
# File lib/callable_tree/node/hooks/call.rb, line 16 def around_call(&block) around_callbacks << block self end
around_callbacks()
click to toggle source
# File lib/callable_tree/node/hooks/call.rb, line 46 def around_callbacks @around_callbacks ||= [] end
before_call(&block)
click to toggle source
# File lib/callable_tree/node/hooks/call.rb, line 11 def before_call(&block) before_callbacks << block self end
before_callbacks()
click to toggle source
# File lib/callable_tree/node/hooks/call.rb, line 42 def before_callbacks @before_callbacks ||= [] end
call(input = nil, **options)
click to toggle source
Calls superclass method
# File lib/callable_tree/node/hooks/call.rb, line 26 def call(input = nil, **options) input = before_callbacks.reduce(input) do |input, callable| callable.call(input, self, **options) end output = super(input, **options) output = around_callbacks.reduce(output) do |output, callable| callable.call(input, self, **options) { output } end after_callbacks.reduce(output) do |output, callable| callable.call(output, self, **options) end end
Private Instance Methods
initialize_copy(_node)
click to toggle source
Calls superclass method
# File lib/callable_tree/node/hooks/call.rb, line 58 def initialize_copy(_node) super self.before_callbacks = before_callbacks.map(&:itself) self.around_callbacks = around_callbacks.map(&:itself) self.after_callbacks = after_callbacks.map(&:itself) end