Class: Aric::JobHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/aric/job_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

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_hashHash<Class, Symbol>

Avalable jobs names and Class that them contain

Returns:

  • (Hash<Class, Symbol>)


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

.jobsArray<Symbol>

Avalable jobs names

Returns:

  • (Array<Symbol>)


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