Sha256: 759d440a07329d26f2321a05f4158aba45bdf32618ef0d212439e5e0eadb75c4

Contents?: true

Size: 1.66 KB

Versions: 10

Compression:

Stored size: 1.66 KB

Contents

module Rake
  module Funnel
    module Support
      module ArgumentMapper
        module Styles
          class MSDeploy
            attr_reader :prefix, :separator, :value_separator, :value_list_separator

            def initialize
              @prefix = '-'
              @separator = ':'
              @value_separator = '='
              @value_list_separator = ','
            end

            def generate_from(model)
              model.flat_map do |switch|
                switch.values.map do |item|
                  values = if item.is_a?(Enumerable)
                             item.map.with_index { |nested, index| nested(nested, index) }
                           else
                             nested(item)
                           end

                  (top_level(switch) + values).flatten
                end
              end
            end

            private

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

            def nested(value, index = 0) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
              res = []
              res << value_list_separator unless index.zero?
              res << separator unless value.key.nil? && value.value.nil? || index != 0
              res << quote(value.key)
              res << value_separator unless value.key.nil? || value.value.nil?
              res << quote(value.value)
              res.compact
            end

            def quote(value)
              value = value.gsub(/"/, '""') if value.is_a?(String)
              return %("#{value}") if value =~ /\s/
              value
            end
          end
        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/argument_mapper/styles/msdeploy.rb
rake-funnel-0.22.1 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.22.0 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.21.2 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.21.1 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.21.0 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.20.2 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.20.1 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.20.0 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.19.0 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb