Sha256: d0a76aa7b879805ab1b8ebf10e4adfb97e00b5054c356e4232766576c76bc5e2

Contents?: true

Size: 904 Bytes

Versions: 72

Compression:

Stored size: 904 Bytes

Contents

require 'yaml'

module Itamae
  class Config
    CONFIG_MATCHER = /(-c|--config) +([^ ]+)/

    def initialize(options)
      @options = options
    end

    def load
      return @options unless config_given?

      configs, options = parse_options
      configs.each do |config|
        options += load_config(config)
      end
      options
    end

    private

    def parse_options
      configs = []
      parsed_option = joined_options.gsub(CONFIG_MATCHER).each do |match|
        configs << Regexp.last_match[2]
        next ''
      end
      [configs, parsed_option.split(' ')]
    end

    def load_config(config)
      YAML.load(open(config)).inject([]) do |options, (key, value)|
        options + ["--#{key}", value.to_s]
      end
    end

    def config_given?
      joined_options =~ CONFIG_MATCHER
    end

    def joined_options
      @option ||= @options.join(' ')
    end
  end
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
itamae-1.7.0 lib/itamae/config.rb
itamae-1.7.0.pre lib/itamae/config.rb
itamae-1.6.3 lib/itamae/config.rb
itamae-1.6.2 lib/itamae/config.rb
itamae-1.6.1 lib/itamae/config.rb
itamae-1.6.0 lib/itamae/config.rb
itamae-1.5.2 lib/itamae/config.rb
itamae-1.5.1 lib/itamae/config.rb
itamae-1.5.0 lib/itamae/config.rb
itamae-1.4.5 lib/itamae/config.rb
itamae-1.4.4 lib/itamae/config.rb
itamae-1.4.3 lib/itamae/config.rb
itamae-1.4.2 lib/itamae/config.rb
itamae-1.4.1 lib/itamae/config.rb
itamae-1.4.0 lib/itamae/config.rb
itamae-1.3.6 lib/itamae/config.rb
itamae-1.3.5 lib/itamae/config.rb
itamae-1.3.4 lib/itamae/config.rb
itamae-1.3.3 lib/itamae/config.rb
itamae-1.3.2 lib/itamae/config.rb