Class: Sprout::StringsParam

Inherits:
TaskParam show all
Defined in:
lib/sprout/tasks/tool_task.rb

Overview

Concrete param object for collections of strings

Direct Known Subclasses

FilesParam, SymbolsParam, UrlsParam

Instance Attribute Summary

Attributes inherited from TaskParam

#belongs_to, #description, #file_expression, #hidden_name, #hidden_value, #name, #prefix, #preprocessable, #required, #shell_name, #to_shell_proc, #type, #validator, #visible

Instance Method Summary collapse

Methods inherited from TaskParam

#hidden_name?, #hidden_value?, #init, #prepare, #prepare_prerequisites, #required?, #shell_value, #to_rdoc, #validate

Instance Method Details

#delimiterObject

Default delimiter is = This is what will appear between each name/value pair as in: “source_path=src source_path+=test source_path+=lib”



766
767
768
# File 'lib/sprout/tasks/tool_task.rb', line 766

def delimiter
  @delimiter ||= "+="
end

#to_shellObject

Returns a shell formatted string of the collection



771
772
773
774
775
776
777
778
779
# File 'lib/sprout/tasks/tool_task.rb', line 771

def to_shell
  return @to_shell_proc.call(self) if(!@to_shell_proc.nil?)

  result = []
  value.each do |str|
    result << "#{shell_name}#{delimiter}#{str}"
  end
  return result.join(' ')
end

#valueObject

Files lists are initialized to an empty array by default



753
754
755
# File 'lib/sprout/tasks/tool_task.rb', line 753

def value
  @value ||= []
end

#value=(val) ⇒ Object

:nodoc:



744
745
746
747
748
749
750
# File 'lib/sprout/tasks/tool_task.rb', line 744

def value=(val)
  if(val.is_a?(String))
    message = "The #{name} property is an Array, not a String. It looks like you may have used the assignment operator (=) where the append operator (<<) was expected."
    raise ToolTaskError.new(message)
  end
  @value = val
end

#visible?Boolean

By default, the FilesParams will not appear in the shell output if there are zero items in the collection

Returns:

  • (Boolean)


759
760
761
# File 'lib/sprout/tasks/tool_task.rb', line 759

def visible?
  @visible ||= (value && value.size > 0)   
end