Class: Skytap::Option
- Inherits:
-
Object
- Object
- Skytap::Option
- Defined in:
- lib/skytap/command_line.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #choices ⇒ Object
-
#initialize(name, options = {}) ⇒ Option
constructor
A new instance of Option.
- #negatable? ⇒ Boolean
- #show_default? ⇒ Boolean
- #signature ⇒ Object
- #switch? ⇒ Boolean
- #val ⇒ Object
- #val=(v) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Option
Returns a new instance of Option.
96 97 98 99 100 101 |
# File 'lib/skytap/command_line.rb', line 96 def initialize(name, = {}) @name = name.to_s @options = .symbolize_keys @desc = @options[:desc] @default = @options[:default] end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
94 95 96 |
# File 'lib/skytap/command_line.rb', line 94 def default @default end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
94 95 96 |
# File 'lib/skytap/command_line.rb', line 94 def desc @desc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
94 95 96 |
# File 'lib/skytap/command_line.rb', line 94 def name @name end |
Instance Method Details
#choices ⇒ Object
141 142 143 |
# File 'lib/skytap/command_line.rb', line 141 def choices @options[:in] end |
#negatable? ⇒ Boolean
111 112 113 |
# File 'lib/skytap/command_line.rb', line 111 def negatable? switch? && @options[:negatable] end |
#show_default? ⇒ Boolean
103 104 105 |
# File 'lib/skytap/command_line.rb', line 103 def show_default? !@options[:hide_default_value] end |
#signature ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/skytap/command_line.rb', line 132 def signature if switch? negation = '[no-]' if negatable? "--#{negation}#{name}" else "--#{name}=#{name.upcase}" end end |
#switch? ⇒ Boolean
107 108 109 |
# File 'lib/skytap/command_line.rb', line 107 def switch? @options[:switch] end |
#val ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/skytap/command_line.rb', line 115 def val if @set @val else default end end |
#val=(v) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/skytap/command_line.rb', line 123 def val=(v) @set = true if switch? @val = !!v else @val = v end end |