Sha256: 238257d003598a00860eb53cefa45b2f36d06cd789ffd5b6c4ded41484c45bbc

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

Dir[File.join(File.dirname(__FILE__), 'argument_mapper', '*.rb')].each do |path|
  require path
end

module Rake::Funnel::Support
  class Mapper
    include Rake::Funnel::Support::ArgumentMapper
    include InstantiateSymbol
    instantiate Styles

    def initialize(style = :Default)
      raise "You cannot use the 'nil' mapper style. Available mappers are: #{available.inspect}" if style.nil?

      @style = create(style)
    end

    def map(args = {})
      model = (args || {}).map { |switch, value|
        value = [value] unless value.kind_of?(Array)

        values = value.map do |val|
          get_values(val)
        end

        Switch.new(switch, values)
      }.flatten

      @style
        .generate_from(model)
        .map { |args| args.map { |arg| camel_case_symbols(arg) }}
        .map(&:join)
    end

    private
    def get_values(value)
      if value.kind_of?(Enumerable)
        pairs = value.map { |k, v|
          KeyValuePair.new(k, v)
        }

        return Array.new(pairs) if value.kind_of?(Array)
        pairs
      else
        Value.new(value)
      end
    end

    def camel_case_symbols(value)
      return value unless value.kind_of?(Symbol)
      value.camelize
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rake-funnel-0.3.2.pre lib/rake/funnel/support/mapper.rb
rake-funnel-0.3.1.pre lib/rake/funnel/support/mapper.rb
rake-funnel-0.3.0.pre lib/rake/funnel/support/mapper.rb
rake-funnel-0.2.0.pre lib/rake/funnel/support/mapper.rb
rake-funnel-0.1.0.pre lib/rake/funnel/support/mapper.rb