Sha256: d35a1ec66247ddb51c8a6cc3924ee55f737e4290c6f6bf27f2f7c26bd1259f01

Contents?: true

Size: 1.4 KB

Versions: 25

Compression:

Stored size: 1.4 KB

Contents

module Sprout

  module Executable
    # Included by any parameters that represent
    # a collection of values, rather than a single
    # value.
    # 
    # Should only be included by classes that 
    # extend Sprout::Executable::Param.
    #
    module CollectionParam

      def initialize
        super
        @value = []
        @delimiter = "+="
        @option_parser_type_name = 'a,b,c'
      end

      # Assign the value and raise if 
      def value=(val)
        if(val.is_a?(String) || !val.is_a?(Enumerable))
          message = "The #{name} property is an Enumerable. It looks like you may have used the assignment operator (=) with (#{value.inspect}) where the append operator (<<) was expected."
          raise Sprout::Errors::ExecutableError.new(message)
        end
        @value = val
      end

      # Hide the collection param if no items
      # have been added to it.
      def visible?
        (!value.nil? && value.size > 0)
      end

      # Returns a shell formatted string of the collection
      def to_shell
        prepare if !prepared?
        validate
        return '' if !visible?
        return @to_shell_proc.call(self) unless @to_shell_proc.nil?
        return value.join(' ') if hidden_name?
        return to_shell_value.collect { |val|
          "#{shell_name}#{delimiter}#{val}"
        }.join(' ')
      end

      def to_shell_value
        value
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sprout-1.0.32.pre lib/sprout/executable/collection_param.rb
sprout-1.0.31.pre lib/sprout/executable/collection_param.rb
sprout-1.0.29.pre lib/sprout/executable/collection_param.rb
sprout-1.0.26.pre lib/sprout/executable/collection_param.rb
sprout-1.0.25.pre lib/sprout/executable/collection_param.rb
sprout-1.0.24.pre lib/sprout/executable/collection_param.rb
sprout-1.0.23.pre lib/sprout/executable/collection_param.rb
sprout-1.0.22.pre lib/sprout/executable/collection_param.rb
sprout-1.0.20.pre lib/sprout/executable/collection_param.rb
sprout-1.0.19.pre lib/sprout/executable/collection_param.rb
sprout-1.0.18.pre lib/sprout/executable/collection_param.rb
sprout-1.0.17.pre lib/sprout/executable/collection_param.rb
sprout-1.0.16.pre lib/sprout/executable/collection_param.rb
sprout-1.0.15.pre lib/sprout/executable/collection_param.rb
sprout-1.0.14.pre lib/sprout/executable/collection_param.rb
sprout-1.0.13.pre lib/sprout/executable/collection_param.rb
sprout-1.0.11.pre lib/sprout/executable/collection_param.rb
sprout-1.0.9.pre lib/sprout/executable/collection_param.rb
sprout-1.0.8.pre lib/sprout/executable/collection_param.rb
sprout-1.0.5.pre lib/sprout/executable/collection_param.rb