Class: MongoMapper::Plugins::Callbacks::Callback

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Callback.



173
174
175
176
177
178
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 173

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.



171
172
173
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 171

def identifier
  @identifier
end

#kindObject (readonly)

Returns the value of attribute kind.



171
172
173
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 171

def kind
  @kind
end

#methodObject (readonly)

Returns the value of attribute method.



171
172
173
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 171

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



171
172
173
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 171

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



180
181
182
183
184
185
186
187
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 180

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



205
206
207
208
209
210
211
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 205

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



193
194
195
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 193

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

#eql?(other) ⇒ Boolean

Returns:



189
190
191
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 189

def eql?(other)
  self == other
end

#hashObject



197
198
199
200
201
202
203
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 197

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