Sha256: de5a66903b98e2f7748070bd414191875ec3337fc6c4325e7e02e85c395b3a29

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

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

module Rake
  module Funnel
    module Support
      class Mapper
        include 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 = {}) # rubocop:disable Metrics/MethodLength
          model = (args || {}).map do |switch, value|
            value = [value] unless value.is_a?(Array)

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

            Switch.new(switch, values)
          end.flatten

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

        private

        def get_values(value)
          if value.is_a?(Enumerable)
            pairs = value.map do |k, v|
              KeyValuePair.new(k, v)
            end

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rake-funnel-0.22.2 lib/rake/funnel/support/mapper.rb
rake-funnel-0.22.1 lib/rake/funnel/support/mapper.rb
rake-funnel-0.22.0 lib/rake/funnel/support/mapper.rb
rake-funnel-0.21.2 lib/rake/funnel/support/mapper.rb
rake-funnel-0.21.1 lib/rake/funnel/support/mapper.rb
rake-funnel-0.21.0 lib/rake/funnel/support/mapper.rb
rake-funnel-0.20.2 lib/rake/funnel/support/mapper.rb
rake-funnel-0.20.1 lib/rake/funnel/support/mapper.rb
rake-funnel-0.20.0 lib/rake/funnel/support/mapper.rb
rake-funnel-0.19.0 lib/rake/funnel/support/mapper.rb