Sha256: 6f8ab34af091a89068539094420778fca8c5073c0a8355ee605528082170c13b

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

require 'active_support/core_ext/string'
require 'active_support/core_ext/hash'

module Balancer
  class OptionTransformer
    def to_cli(options)
      params = []
      options.each do |k,v|
        case v
        when Symbol, String, Integer
          params << key_to_cli_option(k) + ' ' + v.to_s
        when Array
          values = []
          v.each do |o|
            if o.is_a?(Hash)
              o.each do |x,y|
                values << "#{x.to_s.camelize}=#{y}"
              end
            else # assume string
              values << o
            end
          end

          list = v.first.is_a?(Hash) ? values.join(',') : values.join(' ')
          params << key_to_cli_option(k) + ' ' + list
        else
          puts "v.class: #{v.class.inspect}"
          raise "the roof"
        end
      end
      params.join(' ')
    end

    # resource_arns => --resource-arns
    def key_to_cli_option(key)
      '--' + key.to_s.gsub('_','-')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
balancer-0.2.0 lib/balancer/option_transformer.rb