Sha256: 651bbdf4161b1d5b222eb91d43f004dd91358304e013e5eccdc05de4ccfc4d29

Contents?: true

Size: 1.57 KB

Versions: 18

Compression:

Stored size: 1.57 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.map { |switch|
                switch.values.map { |item|
                  if item.is_a?(Enumerable)
                    values = item.map.with_index { |nested, index| nested(nested, index) }
                  else
                    values = nested(item)
                  end

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

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

            def nested(value, index = 0)
              res = []
              res << value_list_separator unless index == 0
              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

18 entries across 18 versions & 1 rubygems

Version Path
rake-funnel-0.18.0 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.17.0 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.16.1 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.16.0 lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.15.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.14.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.13.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.12.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.11.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.10.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.9.1.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.9.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.8.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.7.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.6.1.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.6.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.5.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb
rake-funnel-0.4.0.pre lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb