Module: Anyway::OptparseConfig

Included in:
Config
Defined in:
lib/anyway/optparse_config.rb

Overview

Adds ability to use script options as the source of configuration (via optparse)

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



90
91
92
# File 'lib/anyway/optparse_config.rb', line 90

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#option_parserObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/anyway/optparse_config.rb', line 72

def option_parser
  @option_parser ||= begin
    OptionParserBuilder.call(self.class.option_parser_options) do |key, val|
      write_config_attr(key, val)
    end.tap do |parser|
      self.class.option_parser_extensions.map do |extension|
        extension.call(parser, self)
      end
    end
  end
end

#parse_options!(options) ⇒ Object



84
85
86
87
88
# File 'lib/anyway/optparse_config.rb', line 84

def parse_options!(options)
  Tracing.with_trace_source(type: :options) do
    option_parser.parse!(options)
  end
end