Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

51 lines (41 sloc) 1.269 kB
module Daikon
class Configuration
BLANK_KEY = "1234567890"
URL = "https://radish.heroku.com"
FLAGS = ["-u", "-k", "-s"]
OPTIONS = ["redis_url", "api_key", "server_prefix"]
DEFAULTS = ["redis://0.0.0.0:6379", BLANK_KEY, URL]
attr_accessor *OPTIONS
def initialize(argv = [])
@argv = argv
validate_deprecated_options
parse
validate_api_key
end
private
def argv_matches?(regexp)
@argv.any? { |arg| arg =~ regexp }
end
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
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
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
end
end
Jump to Line
Something went wrong with that request. Please try again.