Module: Cuprum::Cli::Metadata::ClassMethods

Defined in:
lib/cuprum/cli/metadata.rb

Overview

Class methods to extend when including Metadata.

Instance Method Summary collapse

Instance Method Details

#abstractObject

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.

Returns:

  • (true, false)

    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

#descriptionString #description(value) ⇒ String

Overloads:

  • #descriptionString

    Returns the description for the command.

    Returns:

    • (String)

      the description for the command.

  • #description(value) ⇒ String

    Sets the description for the command.

    Parameters:

    • value (String)

      the description to set.

    Returns:

    • (String)

      the set description.



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,
      abstract_command_message('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.

Returns:

  • (true, false)

    true if the command defines a description; otherwise false.



54
# File 'lib/cuprum/cli/metadata.rb', line 54

def description? = !defined_description.nil?

#full_descriptionString #full_description(value) ⇒ String

Overloads:

  • #full_descriptionString

    Returns the full description for the command.

    Returns:

    • (String)

      the full description for the command.

  • #full_description(value) ⇒ String

    Sets the full description for the command.

    Parameters:

    • value (String)

      the full description to set.

    Returns:

    • (String)

      the set full description.



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,
      abstract_command_message('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.

Returns:

  • (true, false)

    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_nameString #full_name(value) ⇒ String

Overloads:

  • #full_nameString

    Returns the name of the command, used when calling from a CLI.

    Unless another value is set, defaults to the class name of the command with the following format:

    • Removes the "Commands" namespace and any prior namespace, if any.
    • Removes a "Command" suffix, if any.
    • Converts each remaining segment to snake_case and joins with ":".

    Returns:

    • (String)

      the scoped name for the command.

  • #full_name(value) ⇒ String

    Sets the full name for the command.

    The full name must be in snake_case format joined by ":".

    Parameters:

    • value (String)

      the full name to set.

    Returns:

    • (String)

      the set full name.



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, abstract_command_message('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:  invalid_full_name_format_message
  )

  @full_name = value
end

#namespaceString?

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".

Returns:

  • (String, nil)

    the namespace for the command, or nil if the command's full name is unscoped.

See Also:



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.

Returns:

  • (true, false)

    true if the command defines a namespace; otherwise false.



143
# File 'lib/cuprum/cli/metadata.rb', line 143

def namespace? = !namespace.nil?

#short_nameString

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".

Returns:

  • (String)

    the short name for the command.



155
# File 'lib/cuprum/cli/metadata.rb', line 155

def short_name = full_name&.split(':')&.last