Class: OctocatalogDiff::Cli::Options::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/octocatalog-diff/cli/options.rb

Overview

Define the Option class and newoption() method for use by cli/options/*.rb files

Class Method Summary collapse

Class Method Details

.has_weight(w) ⇒ Object

rubocop:disable Style/PredicateName



26
27
28
# File 'lib/octocatalog-diff/cli/options.rb', line 26

def self.has_weight(w) # rubocop:disable Style/PredicateName
  @weight = w
end

.nameObject



46
47
48
# File 'lib/octocatalog-diff/cli/options.rb', line 46

def self.name
  self::NAME
end

.newoption(name, &block) ⇒ Object



50
51
52
53
54
55
# File 'lib/octocatalog-diff/cli/options.rb', line 50

def self.newoption(name, &block)
  klass = Class.new(OctocatalogDiff::Cli::Options::Option)
  klass.const_set('NAME', name)
  klass.class_exec(&block)
  Options.classes.push(klass)
end

.order_within_weight(w) ⇒ Object

rubocop:disable Style/TrivialAccessors



30
31
32
# File 'lib/octocatalog-diff/cli/options.rb', line 30

def self.order_within_weight(w) # rubocop:disable Style/TrivialAccessors
  @order_within_weight = w
end

.weightObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/octocatalog-diff/cli/options.rb', line 34

def self.weight
  if @weight && @order_within_weight
    @weight + (@order_within_weight / 100.0)
  elsif @weight
    @weight
  else
    # :nocov:
    raise ArgumentError, "Option #{name} does not have a weight specified. Add 'has_weight NNN' to control ordering."
    # :nocov:
  end
end