Class: Sprout::TaskParam

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

Overview

The base class for all ToolTask parameters. This class is extended by a variety of concrete implementations.

At the time of this writing, only the :boolean TaskParam modifies the interface by adding the show_on_false attribute.

Some other helpful features are as follows:

:file, :files, :path and :paths will all add any items that have been added to their values as file task prerequisites. This is especially helpful when writing rake tasks for Command Line Interface (CLI) compilers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#belongs_toObject

Returns the value of attribute belongs_to.



440
441
442
# File 'lib/sprout/tasks/tool_task.rb', line 440

def belongs_to
  @belongs_to
end

#delimiterObject

ToolParams join their name/value pair with an equals sign by default, this can be modified To a space or whatever you wish



525
526
527
# File 'lib/sprout/tasks/tool_task.rb', line 525

def delimiter
  @delimiter ||= '='
end

#descriptionObject

Returns the value of attribute description.



441
442
443
# File 'lib/sprout/tasks/tool_task.rb', line 441

def description
  @description
end

#file_expressionObject

:nodoc:



518
519
520
# File 'lib/sprout/tasks/tool_task.rb', line 518

def file_expression # :nodoc:
  @file_expression ||= belongs_to.default_file_expression
end

#hidden_nameObject

Returns the value of attribute hidden_name.



442
443
444
# File 'lib/sprout/tasks/tool_task.rb', line 442

def hidden_name
  @hidden_name
end

#hidden_valueObject

Returns the value of attribute hidden_value.



443
444
445
# File 'lib/sprout/tasks/tool_task.rb', line 443

def hidden_value
  @hidden_value
end

#nameObject

Returns the value of attribute name.



444
445
446
# File 'lib/sprout/tasks/tool_task.rb', line 444

def name
  @name
end

#prefixObject

Leading character for each parameter Can sometimes be an empty string, other times it’s a double dash ‘–’ but usually it’s just a single dash ‘-’



506
507
508
# File 'lib/sprout/tasks/tool_task.rb', line 506

def prefix
  @prefix ||= '-'
end

#preprocessableObject

Returns the value of attribute preprocessable.



445
446
447
# File 'lib/sprout/tasks/tool_task.rb', line 445

def preprocessable
  @preprocessable
end

#requiredObject

Returns the value of attribute required.



446
447
448
# File 'lib/sprout/tasks/tool_task.rb', line 446

def required
  @required
end

#shell_nameObject

Return the name with a single leading dash and underscores replaced with dashes



531
532
533
# File 'lib/sprout/tasks/tool_task.rb', line 531

def shell_name
  @shell_name ||= prefix + name.split('_').join('-')
end

#to_shell_proc=(value) ⇒ Object (writeonly)

Sets the attribute to_shell_proc

Parameters:

  • value

    the value to set the attribute to_shell_proc to.



455
456
457
# File 'lib/sprout/tasks/tool_task.rb', line 455

def to_shell_proc=(value)
  @to_shell_proc = value
end

#typeObject

Returns the value of attribute type.



447
448
449
# File 'lib/sprout/tasks/tool_task.rb', line 447

def type
  @type
end

#validatorObject

Returns the value of attribute validator.



448
449
450
# File 'lib/sprout/tasks/tool_task.rb', line 448

def validator
  @validator
end

#valueObject



510
511
512
# File 'lib/sprout/tasks/tool_task.rb', line 510

def value
  @value
end

#visibleObject

Returns the value of attribute visible.



449
450
451
# File 'lib/sprout/tasks/tool_task.rb', line 449

def visible
  @visible
end

Instance Method Details

#hidden_name?Boolean

Should the param name be hidden from the shell? Used for params like ‘input’ on mxmlc

Returns:

  • (Boolean)


492
493
494
# File 'lib/sprout/tasks/tool_task.rb', line 492

def hidden_name?
  @hidden_name ||= false
end

#hidden_value?Boolean

Should the param value be hidden from the shell? Usually used for Boolean toggles like ‘-debug’

Returns:

  • (Boolean)


498
499
500
# File 'lib/sprout/tasks/tool_task.rb', line 498

def hidden_value?
  @hidden_value ||= false
end

#init {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



463
464
465
# File 'lib/sprout/tasks/tool_task.rb', line 463

def init
  yield self if block_given?
end

#prepareObject



483
484
485
# File 'lib/sprout/tasks/tool_task.rb', line 483

def prepare
  prepare_prerequisites
end

#prepare_prerequisitesObject



487
488
# File 'lib/sprout/tasks/tool_task.rb', line 487

def prepare_prerequisites
end

#required?Boolean

Returns:

  • (Boolean)


473
474
475
# File 'lib/sprout/tasks/tool_task.rb', line 473

def required?
  (required == true)
end

#shell_valueObject



514
515
516
# File 'lib/sprout/tasks/tool_task.rb', line 514

def shell_value
  value.to_s
end

#to_rdocObject

Create a string that can be turned into a file that rdoc can parse to describe the customized or generated task using param name, type and description



551
552
553
554
555
556
557
# File 'lib/sprout/tasks/tool_task.rb', line 551

def to_rdoc
  result = ''
  parts = description.split("\n") unless description.nil?
  result << "# #{parts.join("\n# ")}\n" unless description.nil?
  result << "def #{name}=(#{type})\n  @#{name} = #{type}\nend\n\n"
  return result
end

#to_shellObject



535
536
537
538
539
540
541
542
543
544
545
# File 'lib/sprout/tasks/tool_task.rb', line 535

def to_shell
  if(!@to_shell_proc.nil?)
    return @to_shell_proc.call(self)
  elsif(hidden_name?)
    return shell_value
  elsif(hidden_value?)
    return shell_name
  else
    return "#{shell_name}#{delimiter}#{shell_value}"
  end
end

#validateObject



477
478
479
480
481
# File 'lib/sprout/tasks/tool_task.rb', line 477

def validate
  if(required? && !visible?)
    raise ToolTaskError.new("#{name} is required and must not be nil")
  end
end

#visible?Boolean

By default, ToolParams only appear in the shell output when they are not nil

Returns:

  • (Boolean)


469
470
471
# File 'lib/sprout/tasks/tool_task.rb', line 469

def visible?
  @visible ||= value
end