Class: Bundler::Thor::Argument
Do not use. This class is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/bundler/vendor/thor/lib/thor/parser/argument.rb |
Constant Summary
-
VALID_TYPES =
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 3[:numeric, :hash, :array, :string]
Class Method Summary
- .new(name, options = {}) ⇒ Argument constructor
Instance Attribute Summary
- #banner readonly
- #default readonly
- #description readonly
- #enum readonly
-
#human_name
readonly
Alias for #name.
- #name (also: #human_name) readonly
- #required readonly
- #required? ⇒ Boolean readonly
- #show_default? ⇒ Boolean readonly
- #type readonly
Instance Method Summary
- #enum_to_s
- #print_default
- #usage
- #default_banner protected
- #valid_type?(type) ⇒ Boolean protected
- #validate! protected
Constructor Details
.new(name, options = {}) ⇒ Argument
# 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 = [: ] || @enum = [:enum] validate! # Trigger specific validations end
Instance Attribute Details
#banner (readonly)
[ GitHub ]#default (readonly)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5
attr_reader :name, :description, :enum, :required, :type, :default, :
#description (readonly)
[ GitHub ]#enum (readonly)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5
attr_reader :name, :description, :enum, :required, :type, :default, :
#human_name (readonly)
Alias for #name.
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 6
alias_method :human_name, :name
#name (readonly) Also known as: #human_name
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5
attr_reader :name, :description, :enum, :required, :type, :default, :
#required (readonly)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5
attr_reader :name, :description, :enum, :required, :type, :default, :
#required? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 39
def required? required end
#show_default? ⇒ Boolean
(readonly)
[ GitHub ]
#type (readonly)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 5
attr_reader :name, :description, :enum, :required, :type, :default, :
Instance Method Details
#default_banner (protected)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 71
def case type when :boolean nil when :string, :default human_name.upcase when :numeric "N" when :hash "key:value" when :array "one two three" end end
#enum_to_s
[ GitHub ]#print_default
[ GitHub ]# 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(&:dump).join(" ") else @default end end
#usage
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 35
def usage required? ? : "[#{}]" end
#valid_type?(type) ⇒ Boolean
(protected)
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 67
def valid_type?(type) self.class::VALID_TYPES.include?(type.to_sym) end
#validate! (protected)
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 62
def validate! raise ArgumentError, "An argument cannot be required and have default value." if required? && !default.nil? raise ArgumentError, "An argument cannot have an enum other than an enumerable." if @enum && !@enum.is_a?(Enumerable) end