Class: GoshrineBot::Runner
- Inherits:
-
Object
- Object
- GoshrineBot::Runner
- Defined in:
- lib/goshrine_bot/runner.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #config_path ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #parse_options ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/goshrine_bot/runner.rb', line 15 def initialize # defaults self. = { :server_url => "http://goshrine.com/", :gtp_cmd_line => "gnugo --mode gtp", :debug => false, :idle_shutdown_timeout => 60, :maximum_concurrent_games => nil, :pid_path => "./goshrine_bot.pid" } = if !File.exists?(config_path) puts "You must generate a config file." exit end config = YAML::load(ERB.new(IO.read(config_path)).result) #puts "config = #{config.inspect}" bot_name = ARGV[0] || config.keys.first #puts "bot_name = #{ARGV[0]}" if config[bot_name].nil? puts "No config found for #{bot_name.inspect}" exit end .merge!(config[bot_name]) #puts "Options = #{options.inspect}" [:bot_name] = bot_name start end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/goshrine_bot/runner.rb', line 7 def @options end |
Class Method Details
.run ⇒ Object
10 11 12 |
# File 'lib/goshrine_bot/runner.rb', line 10 def run self.new end |
Instance Method Details
#config_path ⇒ Object
48 49 50 |
# File 'lib/goshrine_bot/runner.rb', line 48 def config_path [:config_path] || "./goshrine_bot.yml" end |
#parse_options ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/goshrine_bot/runner.rb', line 59 def OptionParser.new do |opts| opts.summary_width = 25 opts. = "GoShrineBot (1.0)\n\n", "Usage: goshrine_bot [-c configfile] [bot_name]\n", " goshrine_bot --help\n" opts.separator "" opts.separator ""; opts.separator "Configuration:" opts.on("-c", "--config FILE", String, "Path to configuration file.", "(default: #{[:config_path]})") do |v| [:config_path] = File.(v) end opts.separator ""; opts.separator "Miscellaneous:" opts.on_tail("-?", "--help", "Display this usage information.") do puts "#{opts}\n" exit end end.parse! end |
#start ⇒ Object
52 53 54 55 56 57 |
# File 'lib/goshrine_bot/runner.rb', line 52 def start puts "Starting GoShrine (v#{GoshrineBot::VERSION}) bot client: #{[:bot_name]}." client = Client.new() client.run end |