Module: RCelery::TaskSupport::ClassMethods

Defined in:
lib/rcelery/task_support.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_optionsObject

Returns the value of attribute current_options.



15
16
17
# File 'lib/rcelery/task_support.rb', line 15

def current_options
  @current_options
end

Instance Method Details

#method_added(method) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rcelery/task_support.rb', line 17

def method_added(method)
  return if @current_options.nil?

  mod = self
  klass = Class.new { include mod }
  bound_method = klass.instance_method(method).bind(klass.new)

  task_name = @current_options[:name] ||
    TaskSupport.task_name(mod.name, method)

  task = Task.new(@current_options.merge(
    :name => task_name,
    :method => bound_method
  ))

  # current_options must be nil'ed before we redefine
  # the method as doing so would trigger this method
  # again and cause an infinite loop
  @current_options = nil
  mod.module_eval do
    alias_method :"_#{method}", method

    define_method(method) do |*args|
      if args.length.zero?
        task
      else
        send(:"_#{method}", *args)
      end
    end
  end

  RCelery::Task.all_tasks[task_name] = task
end

#task(options = {}) ⇒ Object



51
52
53
# File 'lib/rcelery/task_support.rb', line 51

def task(options = {})
  @current_options = options
end