Class: Burner::JobSet

Inherits:
Object
  • Object
show all
Defined in:
lib/burner/job_set.rb

Overview

This class understands how jobs fit together as a cohesive unit. It does not know how to use them, but it knows how to group them together in a logical manner following some simple rules, such as:

- Jobs in a set should have unique names (unless the name is blank)
- Subsets of jobs can be extracted, by name, in constant time.

Defined Under Namespace

Classes: DuplicateJobNameError, JobNotFoundError

Instance Method Summary collapse

Constructor Details

#initialize(jobs = []) ⇒ JobSet

Returns a new instance of JobSet.



22
23
24
25
26
# File 'lib/burner/job_set.rb', line 22

def initialize(jobs = [])
  @jobs = Jobs.array(jobs).freeze

  assert_unique_job_names
end

Instance Method Details

#jobs(names = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/burner/job_set.rb', line 28

def jobs(names = nil)
  return @jobs unless names

  Array(names).map do |name|
    job = named_jobs_by_name[name.to_s]

    raise JobNotFoundError, "#{name} was not declared as a job" unless job

    job
  end
end