Class: Sprout::TaskParam
- Inherits:
-
Object
- Object
- Sprout::TaskParam
- 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.
Direct Known Subclasses
BooleanParam, FileParam, NumberParam, PathParam, StringParam, StringsParam, SymbolParam, UrlParam
Instance Attribute Summary collapse
-
#belongs_to ⇒ Object
Returns the value of attribute belongs_to.
-
#delimiter ⇒ Object
ToolParams join their name/value pair with an equals sign by default, this can be modified To a space or whatever you wish.
-
#description ⇒ Object
Returns the value of attribute description.
-
#file_expression ⇒ Object
:nodoc:.
-
#hidden_name ⇒ Object
Returns the value of attribute hidden_name.
-
#hidden_value ⇒ Object
Returns the value of attribute hidden_value.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
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 ‘-’.
-
#preprocessable ⇒ Object
Returns the value of attribute preprocessable.
-
#required ⇒ Object
Returns the value of attribute required.
-
#shell_name ⇒ Object
Return the name with a single leading dash and underscores replaced with dashes.
-
#to_shell_proc ⇒ Object
writeonly
Sets the attribute to_shell_proc.
-
#type ⇒ Object
Returns the value of attribute type.
-
#validator ⇒ Object
Returns the value of attribute validator.
- #value ⇒ Object
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
-
#hidden_name? ⇒ Boolean
Should the param name be hidden from the shell? Used for params like ‘input’ on mxmlc.
-
#hidden_value? ⇒ Boolean
Should the param value be hidden from the shell? Usually used for Boolean toggles like ‘-debug’.
- #init {|_self| ... } ⇒ Object
- #prepare ⇒ Object
- #prepare_prerequisites ⇒ Object
- #required? ⇒ Boolean
- #shell_value ⇒ Object
-
#to_rdoc ⇒ Object
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.
- #to_shell ⇒ Object
- #validate ⇒ Object
-
#visible? ⇒ Boolean
By default, ToolParams only appear in the shell output when they are not nil.
Instance Attribute Details
#belongs_to ⇒ Object
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 |
#delimiter ⇒ Object
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 |
#description ⇒ Object
Returns the value of attribute description.
441 442 443 |
# File 'lib/sprout/tasks/tool_task.rb', line 441 def description @description end |
#file_expression ⇒ Object
: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_name ⇒ Object
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_value ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
444 445 446 |
# File 'lib/sprout/tasks/tool_task.rb', line 444 def name @name end |
#prefix ⇒ Object
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 |
#preprocessable ⇒ Object
Returns the value of attribute preprocessable.
445 446 447 |
# File 'lib/sprout/tasks/tool_task.rb', line 445 def preprocessable @preprocessable end |
#required ⇒ Object
Returns the value of attribute required.
446 447 448 |
# File 'lib/sprout/tasks/tool_task.rb', line 446 def required @required end |
#shell_name ⇒ Object
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
455 456 457 |
# File 'lib/sprout/tasks/tool_task.rb', line 455 def to_shell_proc=(value) @to_shell_proc = value end |
#type ⇒ Object
Returns the value of attribute type.
447 448 449 |
# File 'lib/sprout/tasks/tool_task.rb', line 447 def type @type end |
#validator ⇒ Object
Returns the value of attribute validator.
448 449 450 |
# File 'lib/sprout/tasks/tool_task.rb', line 448 def validator @validator end |
#value ⇒ Object
510 511 512 |
# File 'lib/sprout/tasks/tool_task.rb', line 510 def value @value end |
#visible ⇒ Object
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
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’
498 499 500 |
# File 'lib/sprout/tasks/tool_task.rb', line 498 def hidden_value? @hidden_value ||= false end |
#init {|_self| ... } ⇒ Object
463 464 465 |
# File 'lib/sprout/tasks/tool_task.rb', line 463 def init yield self if block_given? end |
#prepare ⇒ Object
483 484 485 |
# File 'lib/sprout/tasks/tool_task.rb', line 483 def prepare prepare_prerequisites end |
#prepare_prerequisites ⇒ Object
487 488 |
# File 'lib/sprout/tasks/tool_task.rb', line 487 def prepare_prerequisites end |
#required? ⇒ Boolean
473 474 475 |
# File 'lib/sprout/tasks/tool_task.rb', line 473 def required? (required == true) end |
#shell_value ⇒ Object
514 515 516 |
# File 'lib/sprout/tasks/tool_task.rb', line 514 def shell_value value.to_s end |
#to_rdoc ⇒ Object
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_shell ⇒ Object
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 |
#validate ⇒ Object
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
469 470 471 |
# File 'lib/sprout/tasks/tool_task.rb', line 469 def visible? @visible ||= value end |