Class: GameMachine::AppConfig

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/game_machine/app_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAppConfig

Returns a new instance of AppConfig.



9
10
11
12
# File 'lib/game_machine/app_config.rb', line 9

def initialize
  @loaded = false
  @config = OpenStruct.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#loadedObject (readonly)

Returns the value of attribute loaded.



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

def loaded
  @loaded
end

Instance Method Details

#load_configObject



14
15
16
17
18
19
20
# File 'lib/game_machine/app_config.rb', line 14

def load_config
  @config = HoconConfig.config
  if ENV['NODE_HOST']
    set_config_from_env
  end
  @loaded = true
end

#set_config_from_envObject



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
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/game_machine/app_config.rb', line 22

def set_config_from_env
  GameMachine.logger.info "Setting config from ENV"
  config.http.host = ENV['NODE_HOST']
  config.http.port = ENV['WWW_PORT'].to_i

  config.tcp.host = ENV['NODE_HOST']
  config.tcp.port = ENV['TCP_PORT'].to_i

  config.udp.host = ENV['NODE_HOST']
  config.udp.port = ENV['UDP_PORT'].to_i

  config.akka.host = ENV['NODE_HOST']
  config.akka.port = ENV['AKKA_PORT'].to_i

  if ENV['CLOUD_HOST'] && ENV['CLOUD_USER'] && ENV['API_KEY']
    GameMachine.logger.info "Found gamecloud config in ENV"
    config.gamecloud.host = ENV['CLOUD_HOST']
    config.gamecloud.user = ENV['CLOUD_USER']
    config.gamecloud.api_key = ENV['API_KEY']
  end

  if ENV['DB_HOST'] && ENV['DB_PORT']  && ENV['DB_NAME'] && ENV['DB_USER'] && ENV['DB_PASS']
    GameMachine.logger.info "Found database config in ENV"
    config.jdbc.hostname =  ENV['DB_HOST']
    config.jdbc.port =      ENV['DB_PORT']
    config.jdbc.database =  ENV['DB_NAME']
    config.jdbc.username =  ENV['DB_USER']
    config.jdbc.password =  ENV['DB_PASS']
  end

  if ENV['AKKA_SEED_HOST'] && ENV['AKKA_SEED_PORT']
    GameMachine.logger.info "Found Seed in ENV"
    Application.config.seeds << "#{ENV['AKKA_SEED_HOST']}:#{ENV['AKKA_SEED_PORT']}"
  end

end