class Handcuffs::Phases
Phases
encapsulates the list of phases and any interdependencies
Public Class Methods
Source
# File lib/handcuffs/phases.rb, line 8 def initialize(phases) @phases = case phases when Hash phases.each_with_object({}) do |phase, acc| acc[phase[0].to_sym] = Array(phase[1]).map(&:to_sym) end else # Assume each entry depends on all entries before it phases.map(&:to_sym).each_with_object({}) do |phase, acc| acc[phase] = phases.take_while { |defined_phase| defined_phase != phase } end end end
Public Instance Methods
Source
# File lib/handcuffs/phases.rb, line 30 def in_order TSort.tsort( @phases.method(:each_key), ->(phase, &block) { @phases.fetch(phase).each(&block) } ) end
Source
# File lib/handcuffs/phases.rb, line 26 def include?(phase) @phases.include?(phase) end
Source
# File lib/handcuffs/phases.rb, line 37 def prereqs(attempted_phase) @phases.fetch(attempted_phase, []) end
Source
# File lib/handcuffs/phases.rb, line 22 def to_sentence @phases.keys.to_sentence end