Module: Vigilem::Core::Hooks::Callback Abstract
- Included in:
- CallbackProc
- Defined in:
- lib/vigilem/core/hooks/callback.rb
Overview
This module is abstract.
core interface for a callback
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#binding ⇒ Proc
calls super, otherwise it’s just a helpful reminder.
-
#call(*args, &block) ⇒ Object
calls super if defined? otherwise calls to_proc.call(*args, &block).
-
#evaluate(context, *args, &block) ⇒ Array
(also: #[])
evaluates the Callback in the specified context.
-
#to_proc ⇒ Proc
calls super, otherwise it’s just a helper.
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/vigilem/core/hooks/callback.rb', line 7 def @options end |
#result ⇒ Object
Returns the value of attribute result.
7 8 9 |
# File 'lib/vigilem/core/hooks/callback.rb', line 7 def result @result end |
Class Method Details
.new(opts = {}, &block) ⇒ CallbackProc
13 14 15 |
# File 'lib/vigilem/core/hooks/callback.rb', line 13 def self.new(opts={}, &block) CallbackProc.new(opts, &block) end |
Instance Method Details
#binding ⇒ Proc
calls super, otherwise it’s just a helpful reminder
54 55 56 |
# File 'lib/vigilem/core/hooks/callback.rb', line 54 def binding defined?(super) ? super : raise('must overload binding') end |
#call(*args, &block) ⇒ Object
calls super if defined? otherwise calls to_proc.call(*args, &block)
40 41 42 |
# File 'lib/vigilem/core/hooks/callback.rb', line 40 def call(*args, &block) self.result = defined?(super) ? super(*args, &block) : to_proc.call(*args, &block) end |
#evaluate(context, *args, &block) ⇒ Array Also known as: []
evaluates the Callback in the specified context
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vigilem/core/hooks/callback.rb', line 22 def evaluate(context, *args, &block) self.result = if block context.define_singleton_method(:__callback__, &self) ret = context.send :__callback__, *args, &block context.class_eval { send :remove_method, :__callback__ } ret else context.instance_exec(*args, &self) end end |
#to_proc ⇒ Proc
calls super, otherwise it’s just a helper
47 48 49 |
# File 'lib/vigilem/core/hooks/callback.rb', line 47 def to_proc defined?(super) ? super : raise('must overload to_proc') end |