Class: Delayed::PerformableMethod

Inherits:
Struct
  • Object
show all
Defined in:
lib/delayed/performable_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

yaml_tag_read_class

Constructor Details

#initialize(object, method, args) ⇒ PerformableMethod

Returns a new instance of PerformableMethod.

Raises:

  • (NoMethodError)


3
4
5
6
7
8
9
# File 'lib/delayed/performable_method.rb', line 3

def initialize(object, method, args)
  raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method, true)

  self.object = object
  self.args   = args
  self.method = method.to_sym
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



19
20
21
# File 'lib/delayed/performable_method.rb', line 19

def method_missing(symbol, *args)
  object.respond_to?(symbol) ? object.send(symbol, *args) : super
end

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



2
3
4
# File 'lib/delayed/performable_method.rb', line 2

def args
  @args
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



2
3
4
# File 'lib/delayed/performable_method.rb', line 2

def method
  @method
end

#objectObject

Returns the value of attribute object

Returns:

  • (Object)

    the current value of object



2
3
4
# File 'lib/delayed/performable_method.rb', line 2

def object
  @object
end

Instance Method Details

#display_nameObject



11
12
13
# File 'lib/delayed/performable_method.rb', line 11

def display_name
  "#{object.class}##{method}"
end

#performObject



15
16
17
# File 'lib/delayed/performable_method.rb', line 15

def perform
  object.send(method, *args) if object
end

#respond_to?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/delayed/performable_method.rb', line 23

def respond_to?(symbol, include_private=false)
  object.respond_to?(symbol, include_private) || super
end