class Daikon::Configuration

Constants

BLANK_KEY
DEFAULTS
FLAGS
OPTIONS

Public Class Methods

new(argv = []) click to toggle source
# File lib/daikon/configuration.rb, line 10
def initialize(argv = [])
  @argv = argv

  validate_deprecated_options
  parse
  validate_api_key
end

Private Instance Methods

argv_matches?(regexp) click to toggle source
# File lib/daikon/configuration.rb, line 20
def argv_matches?(regexp)
  @argv.any? { |arg| arg =~ regexp }
end
parse() click to toggle source
# File lib/daikon/configuration.rb, line 36
def parse
  FLAGS.each_with_index do |flag, flag_index|
    argv_index = @argv.index(flag)
    value = if argv_index
              @argv[argv_index + 1]
            else
              DEFAULTS[flag_index]
            end

    send "#{OPTIONS[flag_index]}=", value
  end
end
validate_api_key() click to toggle source
# File lib/daikon/configuration.rb, line 30
def validate_api_key
  if api_key == BLANK_KEY && argv_matches?(/start|run/)
    abort "Must supply an api key to start the daemon.\nExample: daikon start #{FLAGS[2]} #{DEFAULTS[2]}"
  end
end
validate_deprecated_options() click to toggle source
# File lib/daikon/configuration.rb, line 24
def validate_deprecated_options
  if argv_matches?(/^(\-h|\-p)$/)
    abort "Please use '-u redis://127.0.0.1:6379' format instead to specify redis url"
  end
end