Class: Bundler::Thor::Argument
- Inherits:
-
Object
- Object
- Bundler::Thor::Argument
- Defined in:
- lib/bundler/vendor/thor/lib/thor/parser/argument.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- VALID_TYPES =
[:numeric, :hash, :array, :string]
Instance Attribute Summary collapse
-
#banner ⇒ Object
readonly
Returns the value of attribute banner.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#name ⇒ Object
(also: #human_name)
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #enum_to_s ⇒ Object
-
#initialize(name, options = {}) ⇒ Argument
constructor
A new instance of Argument.
- #print_default ⇒ Object
- #required? ⇒ Boolean
- #show_default? ⇒ Boolean
- #usage ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Argument
Returns a new instance of Argument.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 8 def initialize(name, = {}) class_name = self.class.name.split("::").last type = [:type] raise ArgumentError, "#{class_name} name can't be nil." if name.nil? raise ArgumentError, "Type :#{type} is not valid for #{class_name.downcase}s." if type && !valid_type?(type) @name = name.to_s @description = [:desc] @required = .key?(:required) ? [:required] : true @type = (type || :string).to_sym @default = [:default] @banner = [:banner] || @enum = [:enum] validate! # Trigger specific validations end |
Instance Attribute Details
#banner ⇒ Object (readonly)
Returns the value of attribute banner.
5 6 7 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5 def @banner end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
5 6 7 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5 def description @description end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
5 6 7 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5 def enum @enum end |
#name ⇒ Object (readonly) Also known as: human_name
Returns the value of attribute name.
5 6 7 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
5 6 7 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5 def type @type end |
Instance Method Details
#enum_to_s ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 55 def enum_to_s if enum.respond_to? :join enum.join(", ") else "#{enum.first}..#{enum.last}" end end |
#print_default ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 27 def print_default if @type == :array and @default.is_a?(Array) @default.map { |x| p = x.gsub('"','\\"') "\"#{p}\"" }.join(" ") else @default end end |
#required? ⇒ Boolean
42 43 44 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 42 def required? required end |
#show_default? ⇒ Boolean
46 47 48 49 50 51 52 53 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 46 def show_default? case default when Array, String, Hash !default.empty? else default end end |
#usage ⇒ Object
38 39 40 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 38 def usage required? ? : "[#{}]" end |