Class: GameMachine::Console::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/game_machine/console/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Server

Returns a new instance of Server.



7
8
9
# File 'lib/game_machine/console/server.rb', line 7

def initialize(argv)
  @options = parse_arguments(argv)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/game_machine/console/server.rb', line 6

def options
  @options
end

Instance Method Details

#check_start_dirObject



11
12
13
14
15
16
17
# File 'lib/game_machine/console/server.rb', line 11

def check_start_dir
  java_dir = File.join(File.expand_path(Dir.pwd),'java')
  unless File.directory?(java_dir)
    puts "Please run game_machine from your game directory"
    exit 1
  end
end

#parse_arguments(arguments) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/game_machine/console/server.rb', line 31

def parse_arguments(arguments)
  options = {}

  OptionParser.new do |opt|
    opt.banner = "Usage: game_machine server [options]"
    opt.on('-c', '--config=name', String, 'Configuration file') { |v| options[:config] = v.strip }
    opt.on("-e", "--environment=name", String,
            "Specifies the environment to run under (development/production).",
            "Default: development") { |v| options[:environment] = v.strip }
    opt.parse!(arguments)
  end
  

  unless options.has_key?(:environment)
    options[:environment] = 'development'
  end

  options
end

#run!Object



23
24
25
26
27
28
29
# File 'lib/game_machine/console/server.rb', line 23

def run!
  check_start_dir

  GameMachine.logger.info "Starting with options = #{options.inspect}"
  GameMachine::Application.initialize!
  GameMachine::Application.start
end

#set_environmentObject



19
20
21
# File 'lib/game_machine/console/server.rb', line 19

def set_environment
  ENV['GAME_ENV'] = options[:environment]
end