Module: Woodhouse::Worker::ClassMethods

Defined in:
lib/woodhouse/worker.rb

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)

You can dispatch a job baz on class FooBar by calling FooBar.async_baz.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/woodhouse/worker.rb', line 84

def method_missing(method, *args, &block)
  if method.to_s =~ /^asynch?_(.*)/
    if instance_methods(false).detect{|meth| meth.to_s == $1 }
      Woodhouse.dispatch(@worker_name, $1, args.first)
    else
      super
    end
  else
    super
  end
end

Instance Method Details

- (Object) available_jobs



71
72
73
# File 'lib/woodhouse/worker.rb', line 71

def available_jobs
  @available_jobs ||= public_instance_methods(false)
end

- (Object) exclude_jobs(*jobs)



79
80
81
# File 'lib/woodhouse/worker.rb', line 79

def exclude_jobs(*jobs)
  @available_jobs -= jobs
end

- (Object) only_jobs(*jobs)



75
76
77
# File 'lib/woodhouse/worker.rb', line 75

def only_jobs(*jobs)
  @available_jobs = jobs
end

- (Object) set_worker_name(name)

Sets the name for this worker class if not already set (i.e., if it's an anonymous class). The first time the name for the worker is set, it becomes registered with MixinRegistry. After that, attempting to change the worker class will raise ArgumentError.



60
61
62
63
64
65
66
67
68
69
# File 'lib/woodhouse/worker.rb', line 60

def set_worker_name(name)
  if @worker_name
    raise ArgumentError, "cannot change worker name"
  else
    if name and !name.empty?
      @worker_name = name.to_sym
      Woodhouse::MixinRegistry.register self
    end
  end
end

- (Object) worker_name



52
53
54
# File 'lib/woodhouse/worker.rb', line 52

def worker_name
  @worker_name
end