Class: GitCommander::Command::Option Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/git_commander/command/option.rb

Overview

This class is abstract.

Wraps [Command] arguments, flags, and switches in a generic object to normalize their representation in the context of a [Command].

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, default: nil, description: nil, value: nil) ⇒ Option

Creates a [Option] object.

Parameters:

  • name (String, Symbol)

    the name of the option, these are unique per [Command]

  • default (anything) (defaults to: nil)

    the default value the option should have

  • description (String) (defaults to: nil)

    a description of the option for display in the [Command]‘s help text

  • value (anything) (defaults to: nil)

    a value for the option



19
20
21
22
23
24
# File 'lib/git_commander/command/option.rb', line 19

def initialize(name:, default: nil, description: nil, value: nil)
  @name = name.to_sym
  @default = default
  @description = description
  @value = value
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



9
10
11
# File 'lib/git_commander/command/option.rb', line 9

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/git_commander/command/option.rb', line 9

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/git_commander/command/option.rb', line 9

def name
  @name
end

#valueObject



26
27
28
# File 'lib/git_commander/command/option.rb', line 26

def value
  @value || @default
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



30
31
32
33
34
35
# File 'lib/git_commander/command/option.rb', line 30

def ==(other)
  other.class == self.class &&
    other.name == name &&
    other.default == default &&
    other.description == description
end

#to_hObject



38
39
40
# File 'lib/git_commander/command/option.rb', line 38

def to_h
  { name => value }
end