Module: Cuprum::Cli::Metadata::ClassMethods
- Defined in:
- lib/cuprum/cli/metadata.rb
Overview
Class methods to extend when including Metadata.
Instance Method Summary collapse
-
#abstract ⇒ Object
Marks the command as abstract.
-
#abstract? ⇒ true, false
True if the command is abstract and should not be instantiated directly or assigned metadata; otherwise false.
- #description(value = UNDEFINED) ⇒ Object
-
#description? ⇒ true, false
True if the command defines a description; otherwise false.
- #full_description(value = UNDEFINED) ⇒ Object
-
#full_description? ⇒ true, false
True if the command defines a full description; otherwise false.
- #full_name(value = UNDEFINED) ⇒ Object
-
#namespace ⇒ String?
The namespace for the command.
-
#namespace? ⇒ true, false
True if the command defines a namespace; otherwise false.
-
#short_name ⇒ String
The short name for the command.
Instance Method Details
#abstract ⇒ Object
Marks the command as abstract.
24 |
# File 'lib/cuprum/cli/metadata.rb', line 24 def abstract = @abstract = true |
#abstract? ⇒ true, false
Returns true if the command is abstract and should not be instantiated directly or assigned metadata; otherwise false.
28 |
# File 'lib/cuprum/cli/metadata.rb', line 28 def abstract? = @abstract.nil? ? false : @abstract |
#description ⇒ String #description(value) ⇒ String
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cuprum/cli/metadata.rb', line 39 def description(value = UNDEFINED) return defined_description if value == UNDEFINED if abstract? raise AbstractCommandError, ('set description') end tools.assertions.validate_name(value, as: 'description') @description = value end |
#description? ⇒ true, false
Returns true if the command defines a description; otherwise false.
54 |
# File 'lib/cuprum/cli/metadata.rb', line 54 def description? = !defined_description.nil? |
#full_description ⇒ String #full_description(value) ⇒ String
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cuprum/cli/metadata.rb', line 65 def full_description(value = UNDEFINED) if value == UNDEFINED return defined_full_description || defined_description end if abstract? raise AbstractCommandError, ('set full_description') end tools.assertions.validate_name(value, as: 'full_description') @full_description = value end |
#full_description? ⇒ true, false
Returns true if the command defines a full description; otherwise false.
82 |
# File 'lib/cuprum/cli/metadata.rb', line 82 def full_description? = !defined_full_description.nil? |
#full_name ⇒ String #full_name(value) ⇒ String
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/cuprum/cli/metadata.rb', line 104 def full_name(value = UNDEFINED) # rubocop:disable Metrics/MethodLength return defined_full_name if value == UNDEFINED if abstract? raise AbstractCommandError, ('set full_name') end tools.assertions.validate_name(value, as: 'full_name') tools.assertions.validate_matches( value, as: 'full_name', expected: FULL_NAME_FORMAT, message: ) @full_name = value end |
#namespace ⇒ String?
The namespace for the command.
A command's namespace is defined as the part of the full name prior to the last segment.
- For a command with full name "custom", the namespace will be nil.
- For a command with full name "category:sub_category:do_something", the namespace will be "category:sub_category".
135 136 137 138 139 |
# File 'lib/cuprum/cli/metadata.rb', line 135 def namespace return if full_name.nil? || !full_name.include?(':') full_name&.sub(/:[\w_]+\z/, '') end |
#namespace? ⇒ true, false
Returns true if the command defines a namespace; otherwise false.
143 |
# File 'lib/cuprum/cli/metadata.rb', line 143 def namespace? = !namespace.nil? |
#short_name ⇒ String
The short name for the command.
A command's short_name is the last segment of the full name.
- For a command with full name "custom", the short_name will be "custom".
- For a command with full name "category:sub_category:do_something", the short_name will be "do_something".
155 |
# File 'lib/cuprum/cli/metadata.rb', line 155 def short_name = full_name&.split(':')&.last |