Class: Sprout::Executable::Boolean
- Inherits:
-
Param
- Object
- Param
- Sprout::Executable::Boolean
- Defined in:
- sprout/lib/sprout/executable/boolean.rb
Overview
Concrete Sprout::Executable::Param object for Boolean values.
By default Boolean parameters have their value set to false and :hidden_value set to true. This means that when they are serialized to the shell, they will usually be represented like:
--name
Rather than:
--name=true
The following example demonstrates a simple use of the Boolean parameter:
class Foo include Sprout::Executable add_param :visible, Boolean end
Constant Summary
Constants inherited from Param
DEFAULT_DELIMITER, DEFAULT_OPTION_PARSER_TYPE_NAME, DEFAULT_PREFIX, DEFAULT_SHORT_PREFIX
Instance Attribute Summary (collapse)
-
- (Object) show_on_false
By default, the Boolean parameter will only be displayed when it's value is true.
Instance Method Summary (collapse)
- - (Object) default_option_parser_declaration
-
- (Boolean) initialize
constructor
A new instance of Boolean.
-
- (Object) value=(value)
Convert string representations of falsiness to something more Booleaney.
- - (Boolean) visible?
Methods inherited from Param
#clean_path, #default, #default=, #file_is_output?, #hidden_name?, #hidden_value?, #option_parser_declaration, #option_parser_name, #option_parser_short_name, #option_parser_type_name, #option_parser_type_output, #prepare, #prepare_prerequisites, #prepared?, #required?, #shell_value, #short_prefix, #to_rdoc, #to_shell, #validate
Constructor Details
- (Boolean) initialize
A new instance of Boolean
52 53 54 55 56 57 58 59 |
# File 'sprout/lib/sprout/executable/boolean.rb', line 52 def initialize super @delimiter = ' ' @option_parser_type_name = 'BOOL' @show_on_false = false @value = false @hidden_value = true end |
Instance Attribute Details
- (Object) show_on_false
By default, the Boolean parameter will only be displayed when it's value is true.
Set :show_on_false to true in order to reverse this rule.
add_param :visible, Boolean, :show_on_false => true
Will make the following:
foo :name do |t| t.visible = false end
Serialize to the shell with:
foo -visible=false
50 51 52 |
# File 'sprout/lib/sprout/executable/boolean.rb', line 50 def show_on_false @show_on_false end |
Instance Method Details
- (Object) default_option_parser_declaration
61 62 63 64 |
# File 'sprout/lib/sprout/executable/boolean.rb', line 61 def default_option_parser_declaration return [prefix, '[no-]', option_parser_name] if default == true super end |
- (Object) value=(value)
Convert string representations of falsiness to something more Booleaney.
69 70 71 72 |
# File 'sprout/lib/sprout/executable/boolean.rb', line 69 def value=(value) value = (value == "false" || value == false) ? false : true super value end |
- (Boolean) visible?
74 75 76 77 78 79 80 81 |
# File 'sprout/lib/sprout/executable/boolean.rb', line 74 def visible? @visible ||= value if(show_on_false) return true unless value else return @visible end end |