Class: Pipes::StageParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pipes/stage_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(stages = nil) ⇒ StageParser

Returns a new instance of StageParser.



5
6
7
8
# File 'lib/pipes/stage_parser.rb', line 5

def initialize(stages = nil)
  @stages = stages || Abyss.configuration.stages.configurations
  resolve_dependencies
end

Instance Method Details

#dependents_for(job) ⇒ Object

Recursively grab dependencies for a given job.



24
25
26
27
28
29
30
31
# File 'lib/pipes/stage_parser.rb', line 24

def dependents_for(job)
  if !@dependencies[job] or @dependencies[job].empty?
    []
  else
    recursive_dependencies = @dependencies[job].map{ |klass| dependents_for(klass) }
    (@dependencies[job] + recursive_dependencies).flatten.uniq
  end
end

#jobs_in_stage(stage) ⇒ Object

Grab all jobs for the given stage.



18
19
20
# File 'lib/pipes/stage_parser.rb', line 18

def jobs_in_stage(stage)
  array_for_stage(@stages[stage])
end

#stage_namesObject

Grab all stage names.



12
13
14
# File 'lib/pipes/stage_parser.rb', line 12

def stage_names
  @stages.keys
end

#stages_with_resolved_dependenciesObject

Normalize configured stages so they have a consistent form.

This will return a structure exactly the same as that defined in the config, except, all the “magic” dependencies (symbols to other stages, references to classes, and arrays of both) have been replaced with the name of the actual dependency, ie the class.

Further, each job has been converted to a hash, with the job as the key and the dependencies as the the values.

This data is normalized so that it can be used within the interface, and what to do about the dependencies is up to the implementation.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pipes/stage_parser.rb', line 46

def stages_with_resolved_dependencies
  # Looping over all stages...
  @stages.inject({}) do |resolved_stages, (name, jobs)|
    # If it's defined with a stage dependency
    jobs, _ = jobs.to_a.first if jobs.is_a? Hash

    # Looping over all jobs...
    resolved_stages[name] = jobs.inject([]) do |resolved_stage, job|
      job = job.keys[0] if job.is_a? Hash
      # Normalze to new hash form
      resolved_stage << {job => @dependencies[job]}
    end
    resolved_stages
  end
end