Class: CheckPlease::Flag
- Inherits:
-
Object
- Object
- CheckPlease::Flag
- Defined in:
- lib/check_please/flag.rb
Instance Attribute Summary collapse
-
#cli_long ⇒ Object
Returns the value of attribute cli_long.
-
#cli_short ⇒ Object
Returns the value of attribute cli_short.
- #default ⇒ Object
-
#default_proc ⇒ Object
Returns the value of attribute default_proc.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #coerce(&block) ⇒ Object
-
#initialize(attrs = {}) {|_self| ... } ⇒ Flag
constructor
A new instance of Flag.
- #mutually_exclusive_to(flag_name) ⇒ Object
- #repeatable ⇒ Object
- #validate(&block) ⇒ Object
Constructor Details
#initialize(attrs = {}) {|_self| ... } ⇒ Flag
Returns a new instance of Flag.
11 12 13 14 15 16 17 18 |
# File 'lib/check_please/flag.rb', line 11 def initialize(attrs = {}) @validators = [] attrs.each do |name, value| set_attribute! name, value end yield self if block_given? freeze end |
Instance Attribute Details
#cli_long ⇒ Object
Returns the value of attribute cli_long.
8 9 10 |
# File 'lib/check_please/flag.rb', line 8 def cli_long @cli_long end |
#cli_short ⇒ Object
Returns the value of attribute cli_short.
9 10 11 |
# File 'lib/check_please/flag.rb', line 9 def cli_short @cli_short end |
#default ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/check_please/flag.rb', line 20 def default if default_proc default_proc.call else @default end end |
#default_proc ⇒ Object
Returns the value of attribute default_proc.
6 7 8 |
# File 'lib/check_please/flag.rb', line 6 def default_proc @default_proc end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/check_please/flag.rb', line 7 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/check_please/flag.rb', line 4 def name @name end |
Instance Method Details
#coerce(&block) ⇒ Object
28 29 30 |
# File 'lib/check_please/flag.rb', line 28 def coerce(&block) @coercer = block end |
#mutually_exclusive_to(flag_name) ⇒ Object
42 43 44 |
# File 'lib/check_please/flag.rb', line 42 def mutually_exclusive_to(flag_name) @validators << ->(flags, _) { flags.send(flag_name).empty? } end |
#repeatable ⇒ Object
46 47 48 49 |
# File 'lib/check_please/flag.rb', line 46 def repeatable @repeatable = true self.default_proc = ->{ Array.new } end |
#validate(&block) ⇒ Object
51 52 53 |
# File 'lib/check_please/flag.rb', line 51 def validate(&block) @validators << block end |