Sha256: 1dd91de612261e5a07ed27641f5cb842a6f35f45453d85ef7037d3f51b1bea6b

Contents?: true

Size: 689 Bytes

Versions: 5

Compression:

Stored size: 689 Bytes

Contents

module Rake::Funnel::Support::ArgumentMapper::Styles
  class Default
    attr_reader :prefix, :value_separator

    def initialize
      @prefix = '/'
      @value_separator = ','
    end

    def generate_from(model)
      model.map { |switch|
        switch.values.flatten.map { |value|
          [top_level(switch), nested(value)].reject(&:empty?)
        }
      }.flatten(2)
    end

    private
    def top_level(switch)
      [prefix, switch.switch]
    end

    def nested(value)
      res = []
      res << value.key
      res << value_separator unless value.key.nil? || value.value.nil?
      res << value.value
      res.compact
    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/argument_mapper/styles/default.rb
rake-funnel-0.3.1.pre lib/rake/funnel/support/argument_mapper/styles/default.rb
rake-funnel-0.3.0.pre lib/rake/funnel/support/argument_mapper/styles/default.rb
rake-funnel-0.2.0.pre lib/rake/funnel/support/argument_mapper/styles/default.rb
rake-funnel-0.1.0.pre lib/rake/funnel/support/argument_mapper/styles/default.rb