Class: Xferase::Config
- Inherits:
-
Object
- Object
- Xferase::Config
- Includes:
- Singleton
- Defined in:
- lib/xferase/config.rb
Constant Summary collapse
- OPTIONS =
[ ['-v', '--verbose', 'print verbose output'], ['-i INBOX', '--inbox=INBOX', 'path to the inbox (required)'], ['-l LIBRARY', '--library=LIBRARY', 'path to the master library (required)'], ['-w LIBRARY_WEB', '--library-web=LIBRARY_WEB', 'path to the web-optimized library'], ].freeze
- OPTION_NAMES =
OPTIONS .flatten .grep(/^--/) .map { |option| option[/\w[a-z\-]+/] } .map(&:to_sym)
Class Method Summary collapse
- .[](key) ⇒ Object
- .method_missing(m, *args, &blk) ⇒ Object
- .parse_opts! ⇒ Object
- .respond_to_missing?(m, *args) ⇒ Boolean
Class Method Details
.[](key) ⇒ Object
47 48 49 |
# File 'lib/xferase/config.rb', line 47 def [](key) @params[key] end |
.method_missing(m, *args, &blk) ⇒ Object
51 52 53 54 |
# File 'lib/xferase/config.rb', line 51 def method_missing(m, *args, &blk) m.to_s.tr('_', '-').to_sym .then { |key| OPTION_NAMES.include?(key) ? self[key] : super } end |
.parse_opts! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/xferase/config.rb', line 24 def parse_opts! @params = {} parser = OptionParser.new do |opts| opts.version = Xferase::VERSION opts. = <<~BANNER Usage: xferase [--version] [-h | --help] [<args>] BANNER OPTIONS.each { |opt| opts.on(*opt) } end.tap { |p| p.parse!(into: @params) } @params.freeze raise "no inbox directory given" if !@params.key?(:inbox) (%i[library library-web] & @params.keys) .then { |dest_dirs| raise "no destination library given" if dest_dirs.empty? } rescue => e warn("#{parser.program_name}: #{e.}") warn(parser.help) if e.is_a?(OptionParser::ParseError) exit 1 end |
.respond_to_missing?(m, *args) ⇒ Boolean
56 57 58 |
# File 'lib/xferase/config.rb', line 56 def respond_to_missing?(m, *args) @params.key?(m.to_s.tr('_', '-').to_sym) || super end |