Sha256: bf205d973548ea701cdfdf51954515584363ef5db40a4cf7dea88ab66b54cf25

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require 'ascii_binder_gabriel_rh/distro'
require 'trollop'
require 'yaml'

module AsciiBinderGabrielRH
  class DistroMap
    def initialize(distro_map_filepath)
      @distro_yaml = YAML.load_file(distro_map_filepath)
      @distro_map  = {}
      @distro_yaml.each do |distro_key,distro_config|
        if @distro_map.has_key?(distro_key)
          Trollop::die "Error parsing '#{distro_map_filepath}': distro key '#{distro_key}' is used more than once."
        end
        distro = AsciiBinderGabrielRH::Distro.new(distro_map_filepath,distro_key,distro_config)
        @distro_map[distro_key] = distro
      end
    end

    def get_distro(distro_key)
      unless @distro_map.has_key?(distro_key)
        Trollop::die "Distro key '#{distro_key}' does not exist"
      end
      @distro_map[distro_key]
    end

    def include_distro_key?(distro_key)
      @distro_map.has_key?(distro_key)
    end

    def distro_keys
      @distro_map.keys
    end

    def distros
      @distro_map.values
    end

    def distro_branches(distro_key='')
      if distro_key == ''
        branch_list = []
        distros.each do |distro|
          branch_list.concat(distro.branch_ids)
        end
        return branch_list.uniq
      else
        return get_distro(distro_key).branch_ids
      end
    end

    def is_valid?
      @distro_map.values.each do |distro|
        next if distro.is_valid?
        return false
      end
      return true
    end

    def errors
      errors = []
      @distro_map.values.each do |distro|
        next if distro.is_valid?
        errors << distro.errors
      end
      return errors
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ascii_binder_gabriel_rh-0.0.1 lib/ascii_binder_gabriel_rh/distro_map.rb