Class: ActiveSupport::Callbacks::Callback

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Callback.



133
134
135
136
137
138
# File 'lib/active_support/callbacks.rb', line 133

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.



131
132
133
# File 'lib/active_support/callbacks.rb', line 131

def identifier
  @identifier
end

#kindObject (readonly)

Returns the value of attribute kind.



131
132
133
# File 'lib/active_support/callbacks.rb', line 131

def kind
  @kind
end

#methodObject (readonly)

Returns the value of attribute method.



131
132
133
# File 'lib/active_support/callbacks.rb', line 131

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



131
132
133
# File 'lib/active_support/callbacks.rb', line 131

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/active_support/callbacks.rb', line 140

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



165
166
167
168
169
170
171
# File 'lib/active_support/callbacks.rb', line 165

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



153
154
155
# File 'lib/active_support/callbacks.rb', line 153

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/active_support/callbacks.rb', line 149

def eql?(other)
  self == other
end

#hashObject



157
158
159
160
161
162
163
# File 'lib/active_support/callbacks.rb', line 157

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