Class: Voltron::Config
- Inherits:
-
Object
- Object
- Voltron::Config
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/voltron/config.rb,
lib/voltron/config/js.rb
Defined Under Namespace
Classes: Js
Instance Attribute Summary collapse
- #base_url ⇒ Object
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #js ⇒ Object
- #merge(data) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
16 17 18 19 20 21 |
# File 'lib/voltron/config.rb', line 16 def initialize @logger ||= ::Logger.new(::Rails.root.join('log', 'voltron.log')) @debug ||= false @log_level ||= Rails.application.config.log_level @base_url ||= (Rails.application.config.action_controller..try(:[], :host) || 'http://localhost:3000') end |
Instance Attribute Details
#base_url ⇒ Object
32 33 34 35 36 37 |
# File 'lib/voltron/config.rb', line 32 def base_url @base_url = "http://#{@base_url}" unless @base_url.strip.start_with?('http') url = URI.parse(@base_url) port = url.port == 80 ? '' : ":#{url.port}" "#{url.scheme}://#{url.host}#{port}" end |
#debug ⇒ Object
Returns the value of attribute debug.
12 13 14 |
# File 'lib/voltron/config.rb', line 12 def debug @debug end |
#log_level ⇒ Object
Returns the value of attribute log_level.
12 13 14 |
# File 'lib/voltron/config.rb', line 12 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/voltron/config.rb', line 12 def logger @logger end |
Instance Method Details
#merge(data) ⇒ Object
28 29 30 |
# File 'lib/voltron/config.rb', line 28 def merge(data) js.custom.merge! data end |
#to_h ⇒ Object
23 24 25 26 |
# File 'lib/voltron/config.rb', line 23 def to_h run_callbacks :generate_voltron_config js.to_h.merge(debug: @debug, log_level: @log_level) end |