Module: Woodhouse::Worker::ClassMethods
- Defined in:
- lib/woodhouse/worker.rb
Instance Method Summary collapse
-
#method_missing(method, *args, &block) ⇒ Object
You can dispatch a job
baz
on classFooBar
by calling FooBar.async_baz. -
#set_worker_name(name) ⇒ Object
Sets the name for this worker class if not already set (i.e., if it’s an anonymous class).
- #worker_name ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
You can dispatch a job baz
on class FooBar
by calling FooBar.async_baz.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/woodhouse/worker.rb', line 72 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
#set_worker_name(name) ⇒ Object
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 |
#worker_name ⇒ Object
52 53 54 |
# File 'lib/woodhouse/worker.rb', line 52 def worker_name @worker_name end |