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