Module: Newshound::Jobs
- Defined in:
- lib/newshound/jobs.rb,
lib/newshound/jobs/que.rb,
lib/newshound/jobs/base.rb
Defined Under Namespace
Class Attribute Summary collapse
-
.registry ⇒ Object
readonly
Returns the value of attribute registry.
Class Method Summary collapse
- .clear_registry! ⇒ Object
-
.register(name, adapter_class) ⇒ Object
Register a job adapter class with a symbolic name.
-
.source(source) ⇒ Jobs::Base
Get a job source adapter instance.
Class Attribute Details
.registry ⇒ Object (readonly)
Returns the value of attribute registry.
10 11 12 |
# File 'lib/newshound/jobs.rb', line 10 def registry @registry end |
Class Method Details
.clear_registry! ⇒ Object
38 39 40 |
# File 'lib/newshound/jobs.rb', line 38 def clear_registry! @registry = {} end |
.register(name, adapter_class) ⇒ Object
Register a job adapter class with a symbolic name
16 17 18 |
# File 'lib/newshound/jobs.rb', line 16 def register(name, adapter_class) @registry[name.to_sym] = adapter_class end |
.source(source) ⇒ Jobs::Base
Get a job source adapter instance
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/newshound/jobs.rb', line 25 def source(source) return source unless source.is_a?(Symbol) if @registry.key?(source) return @registry[source].new end constant = constants.find { |c| c.to_s.gsub(/(?<!^)([A-Z])/, "_\\1").downcase == source.to_s } raise "Invalid job source: #{source}" unless constant const_get(constant).new end |