Class: Voltron::Config

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
lib/voltron/config.rb,
lib/voltron/config/js.rb

Defined Under Namespace

Classes: Js

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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.default_url_options.try(:[], :host) || 'http://localhost:3000')
end

Instance Attribute Details

#base_urlObject



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

#debugObject

Returns the value of attribute debug.



12
13
14
# File 'lib/voltron/config.rb', line 12

def debug
  @debug
end

#log_levelObject

Returns the value of attribute log_level.



12
13
14
# File 'lib/voltron/config.rb', line 12

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/voltron/config.rb', line 12

def logger
  @logger
end

Instance Method Details

#jsObject



4
5
6
# File 'lib/voltron/config/js.rb', line 4

def js
  @js ||= Js.new
end

#merge(data) ⇒ Object



28
29
30
# File 'lib/voltron/config.rb', line 28

def merge(data)
  js.custom.merge! data
end

#to_hObject



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