Class: Jettr::Config
- Inherits:
-
Object
- Object
- Jettr::Config
- Defined in:
- lib/jettr/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #create_app(app_config) ⇒ Object
- #create_server ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #store ⇒ Object
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(={}) @config = Configatron::Store.new if [:config_file] && File.exist?([:config_file]) config.configure_from_yaml([:config_file]) config.base_path = File.(File.dirname([:config_file])) else config.configure_from_hash() end config.server.set_default(:port, 8080) config.set_default(:apps, []) end |
Instance Attribute Details
#config ⇒ Object (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_server ⇒ Object
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.(File.join(config.base_path, app_config[:app_path])) elsif app_config[:app_path] app_config[:app_path] = File.(app_config[:app_path]) end server.handlers << create_app(app_config) puts "Added handler: #{server.handlers.last.inspect}" end server end |
#store ⇒ Object
20 21 22 |
# File 'lib/jettr/config.rb', line 20 def store return @config end |