Class: Aric::JobHandler
- Inherits:
-
Object
- Object
- Aric::JobHandler
- Defined in:
- lib/aric/job_handler.rb
Class Method Summary collapse
-
.job_class_hash ⇒ Hash<Class, Symbol>
Avalable jobs names and Class that them contain.
-
.jobs ⇒ Array<Symbol>
Avalable jobs names.
- .play(*args) ⇒ Object
Instance Method Summary collapse
-
#initialize(job_name) ⇒ JobHandler
constructor
A new instance of JobHandler.
- #run(*args) ⇒ Object
Constructor Details
#initialize(job_name) ⇒ JobHandler
Returns a new instance of JobHandler.
42 43 44 |
# File 'lib/aric/job_handler.rb', line 42 def initialize(job_name) @job_name = job_name.to_sym end |
Class Method Details
.job_class_hash ⇒ Hash<Class, Symbol>
Avalable jobs names and Class that them contain
27 28 29 30 31 |
# File 'lib/aric/job_handler.rb', line 27 def job_class_hash @job_class_hash ||= job_classes.each_with_object({}) do |c, a| a[c] = c.public_instance_methods(false) end end |
.jobs ⇒ Array<Symbol>
Avalable jobs names
21 22 23 |
# File 'lib/aric/job_handler.rb', line 21 def jobs @jobs ||= job_class_hash.values.flat_map(&:itself) end |
.play(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/aric/job_handler.rb', line 8 def play(*args) case when !args.first raise Aric::Error::JobNameRequired.new when !jobs.include?(args.first.to_sym) raise Aric::Error::JobNotFound.new(args.first) else new(:play_music).run(*args) end end |
Instance Method Details
#run(*args) ⇒ Object
46 47 48 |
# File 'lib/aric/job_handler.rb', line 46 def run(*args) job_class.run(@job_name, *args) end |