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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/vigilem/core/hooks/callback.rb', line 7

def options
  @options
end

#resultObject

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

Parameters:

  • opts (Hash) (defaults to: {})
  • block (Proc)

Returns:

See Also:



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

#bindingProc

calls super, otherwise it’s just a helpful reminder

Returns:

  • (Proc)

    ; this object as a Proc

Raises:

  • (RuntimeError)


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)

Parameters:

  • args (Array)
  • block (Proc)

Returns:

  • result

See Also:

  • Proc#call


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

Parameters:

  • context
  • args (Array)
  • block (Proc)

Returns:

  • (Array)


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_procProc

calls super, otherwise it’s just a helper

Returns:

  • (Proc)

    ; this object as a Proc

Raises:

  • (RuntimeError)


47
48
49
# File 'lib/vigilem/core/hooks/callback.rb', line 47

def to_proc
  defined?(super) ? super : raise('must overload to_proc')
end