Class: Jettr::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/jettr/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jettr/config.rb', line 8

def initialize(options={})
  @config = Configatron::Store.new
  if options[:config_file] && File.exist?(options[:config_file])
    config.configure_from_yaml(options[:config_file])
    config.base_path = File.expand_path(File.dirname(options[:config_file]))
  else
    config.configure_from_hash(options)
  end
  config.server.set_default(:port, 8080)
  config.set_default(:apps, [])
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/jettr/config.rb', line 7

def config
  @config
end

Instance Method Details

#create_app(app_config) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/jettr/config.rb', line 40

def create_app(app_config)
  puts "Creating app handler: #{app_config.inspect}"
  app_type = app_config.delete(:type)
  app_type = app_type ? app_type.to_sym : app_type
  handler_class = Jettr::Handler::HANDLERS[app_type] || Jettr::Handler::HANDLERS[:default]
  handler_class.new(app_config)
end

#create_serverObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jettr/config.rb', line 24

def create_server
  puts "Creating server..."
  server = Jettr::Server.new(config.server.to_hash)
  config.apps.each do |app_config|
    app_config.symbolize_keys!
    if app_config[:app_path] && config.exists?(:base_path)
      app_config[:app_path] = File.expand_path(File.join(config.base_path, app_config[:app_path]))
    elsif app_config[:app_path]
      app_config[:app_path] = File.expand_path(app_config[:app_path])
    end
    server.handlers << create_app(app_config)
    puts "Added handler: #{server.handlers.last.inspect}"
  end
  server
end

#storeObject



20
21
22
# File 'lib/jettr/config.rb', line 20

def store
  return @config
end