Class: Inch::CLI::Command::Options::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
TraceHelper, YardoptsHelper
Defined in:
lib/inch/cli/command/options/base.rb

Overview

This class is abstract.

Subclass and override #set_options

Abstract base class for CLI options. Provides some helper methods for the option parser.

Direct Known Subclasses

BaseList, BaseObject

Constant Summary

Constants included from YardoptsHelper

YardoptsHelper::VALID_YARD_SWITCHES

Instance Attribute Summary collapse

Attributes included from YardoptsHelper

#excluded, #yard_files

Class Method Summary collapse

Instance Method Summary collapse

Methods included from YardoptsHelper

#parse_yardopts_options, #yardopts_options

Instance Attribute Details

#uiObject

Returns the value of attribute ui.



45
46
47
# File 'lib/inch/cli/command/options/base.rb', line 45

def ui
  @ui
end

Class Method Details

.attribute(name, default = nil) ⇒ void

This method returns an undefined value.

Creates an attribute with an optional default value

Parameters:

  • name (Symbol)

    the name of the attribute

  • default (nil) (defaults to: nil)

    the default value of the attribute



29
30
31
32
33
34
35
36
# File 'lib/inch/cli/command/options/base.rb', line 29

def attribute(name, default = nil)
  define_method(name) do
    instance_variable_get("@#{name}") || default
  end
  define_method("#{name}=") do |value|
    instance_variable_set("@#{name}", value)
  end
end

Instance Method Details

#parse(args) ⇒ void

This method returns an undefined value.

Parses the given args “into” the current Options object

Parameters:

  • args (Array<String>)

    command-line arguments



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/inch/cli/command/options/base.rb', line 51

def parse(args)
  opts = OptionParser.new
  opts.banner = usage

  descriptions.each do |text|
    opts.separator '  ' + text
  end

  set_options(opts)
  parse_options(opts, args)
end

#set_options(opts) ⇒ void

Note:

Override to fill with individual options

This method returns an undefined value.

Sets all options for the current Options object

Parameters:

  • opts (OptionParser)


69
70
71
# File 'lib/inch/cli/command/options/base.rb', line 69

def set_options(opts)
  common_options(opts)
end

#verifyvoid

Note:

Override to fill with validations

This method returns an undefined value.

Verifies if the given options are valid



78
79
# File 'lib/inch/cli/command/options/base.rb', line 78

def verify
end