Class: Wonkavision::Plugins::Callbacks::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/wonkavision/plugins/callbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, method, options = {}) ⇒ Callback

Returns a new instance of Callback.



114
115
116
117
118
119
# File 'lib/wonkavision/plugins/callbacks.rb', line 114

def initialize(kind, method, options={})
  @kind       = kind
  @method     = method
  @identifier = options[:identifier]
  @options    = options
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



112
113
114
# File 'lib/wonkavision/plugins/callbacks.rb', line 112

def identifier
  @identifier
end

#kindObject (readonly)

Returns the value of attribute kind.



112
113
114
# File 'lib/wonkavision/plugins/callbacks.rb', line 112

def kind
  @kind
end

#methodObject (readonly)

Returns the value of attribute method.



112
113
114
# File 'lib/wonkavision/plugins/callbacks.rb', line 112

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



112
113
114
# File 'lib/wonkavision/plugins/callbacks.rb', line 112

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/wonkavision/plugins/callbacks.rb', line 121

def ==(other)
  case other
    when Callback
      (self.identifier && self.identifier == other.identifier) || self.method == other.method
    else
      (self.identifier && self.identifier == other) || self.method == other
  end
end

#call(*args, &block) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/wonkavision/plugins/callbacks.rb', line 146

def call(*args, &block)
  evaluate_method(method, *args, &block) if should_run_callback?(*args)
rescue LocalJumpError
  raise ArgumentError,
        "Cannot yield from a Proc type filter. The Proc must take two " +
                "arguments and execute #call on the second argument."
end

#dupObject



134
135
136
# File 'lib/wonkavision/plugins/callbacks.rb', line 134

def dup
  self.class.new(@kind, @method, @options.dup)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/wonkavision/plugins/callbacks.rb', line 130

def eql?(other)
  self == other
end

#hashObject



138
139
140
141
142
143
144
# File 'lib/wonkavision/plugins/callbacks.rb', line 138

def hash
  if @identifier
    @identifier.hash
  else
    @method.hash
  end
end