Class: TreasureData::Logger::Agent::Rails::Config
- Inherits:
-
Object
- Object
- TreasureData::Logger::Agent::Rails::Config
- Defined in:
- lib/td/logger/agent/rails/config.rb
Instance Attribute Summary collapse
-
#access_log_table ⇒ Object
readonly
Returns the value of attribute access_log_table.
-
#agent_host ⇒ Object
readonly
Returns the value of attribute agent_host.
-
#agent_port ⇒ Object
readonly
Returns the value of attribute agent_port.
-
#apikey ⇒ Object
readonly
Returns the value of attribute apikey.
-
#auto_create_table ⇒ Object
readonly
Returns the value of attribute auto_create_table.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#debug_mode ⇒ Object
readonly
Returns the value of attribute debug_mode.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Class Method Summary collapse
Instance Method Summary collapse
- #access_log_enabled? ⇒ Boolean
- #agent_mode? ⇒ Boolean
- #assign_conf(conf) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_env ⇒ Object
- #load_file(path) ⇒ Object
- #load_file_ey(path) ⇒ Object
- #load_yaml(path) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
41 42 43 |
# File 'lib/td/logger/agent/rails/config.rb', line 41 def initialize @disabled = false end |
Instance Attribute Details
#access_log_table ⇒ Object (readonly)
Returns the value of attribute access_log_table.
38 39 40 |
# File 'lib/td/logger/agent/rails/config.rb', line 38 def access_log_table @access_log_table end |
#agent_host ⇒ Object (readonly)
Returns the value of attribute agent_host.
36 37 38 |
# File 'lib/td/logger/agent/rails/config.rb', line 36 def agent_host @agent_host end |
#agent_port ⇒ Object (readonly)
Returns the value of attribute agent_port.
36 37 38 |
# File 'lib/td/logger/agent/rails/config.rb', line 36 def agent_port @agent_port end |
#apikey ⇒ Object (readonly)
Returns the value of attribute apikey.
37 38 39 |
# File 'lib/td/logger/agent/rails/config.rb', line 37 def apikey @apikey end |
#auto_create_table ⇒ Object (readonly)
Returns the value of attribute auto_create_table.
37 38 39 |
# File 'lib/td/logger/agent/rails/config.rb', line 37 def auto_create_table @auto_create_table end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
37 38 39 |
# File 'lib/td/logger/agent/rails/config.rb', line 37 def database @database end |
#debug_mode ⇒ Object (readonly)
Returns the value of attribute debug_mode.
38 39 40 |
# File 'lib/td/logger/agent/rails/config.rb', line 38 def debug_mode @debug_mode end |
#disabled ⇒ Object
Returns the value of attribute disabled.
39 40 41 |
# File 'lib/td/logger/agent/rails/config.rb', line 39 def disabled @disabled end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
36 37 38 |
# File 'lib/td/logger/agent/rails/config.rb', line 36 def tag @tag end |
Class Method Details
.init ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/td/logger/agent/rails/config.rb', line 53 def self.init c = Config.new config_path = CONFIG_PATH.start_with?('/') ? CONFIG_PATH : "#{::Rails.root}/#{CONFIG_PATH}" if File.exist?(config_path) c.load_file(config_path) elsif File.exist?(CONFIG_PATH_EY_DEPLOY) c.load_file_ey(CONFIG_PATH_EY_DEPLOY) elsif File.exist?(CONFIG_PATH_EY_LOCAL) c.load_file_ey(CONFIG_PATH_EY_LOCAL) else c.load_env end return c rescue warn "Disabling Treasure Data event logger: #{$!}" c.disabled = true return c end |
Instance Method Details
#access_log_enabled? ⇒ Boolean
49 50 51 |
# File 'lib/td/logger/agent/rails/config.rb', line 49 def access_log_enabled? !@access_log_table.nil? && !@access_log_table.empty? end |
#agent_mode? ⇒ Boolean
45 46 47 |
# File 'lib/td/logger/agent/rails/config.rb', line 45 def agent_mode? @agent_host != nil end |
#assign_conf(conf) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/td/logger/agent/rails/config.rb', line 6 def assign_conf(conf) if agent = conf['agent'] host, port = agent.split(':',2) port = (port || 24224).to_i @agent_host = host @agent_port = port @tag = conf['tag'] @tag ||= conf['database'] raise "'tag' nor 'database' options are not set" unless @tag else @apikey = conf['apikey'] raise "'apikey' option is not set" unless @apikey @database = conf['database'] raise "'database' option is not set" unless @database if conf.has_key?('auto_create_table') @auto_create_table = !!conf['auto_create_table'] else @auto_create_table = true end @debug_mode = !!conf['debug_mode'] end @access_log_table = conf['access_log_table'] end |
#load_env ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/td/logger/agent/rails/config.rb', line 102 def load_env apikey = ENV['TREASURE_DATA_API_KEY'] || ENV['TD_API_KEY'] unless apikey @disabled = true return end assign_conf({ 'apikey' => apikey, 'database' => ENV['TREASURE_DATA_DB'] || "rails_#{::Rails.env}", 'access_log_table' => ENV['TREASURE_DATA_ACCESS_LOG_TABLE'], 'auto_create_table' => true }) end |
#load_file(path) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/td/logger/agent/rails/config.rb', line 74 def load_file(path) conf = load_yaml(path)[::Rails.env] unless conf @disabled = true return end assign_conf(conf) end |
#load_file_ey(path) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/td/logger/agent/rails/config.rb', line 85 def load_file_ey(path) conf = load_yaml(path) apikey = conf['td']['TREASURE_DATA_API_KEY'] if conf.is_a?(Hash) and conf['td'].is_a?(Hash) unless apikey @disabled = true return end assign_conf({ 'apikey' => apikey, 'database' => ENV['TREASURE_DATA_DB'] || "rails_#{::Rails.env}", 'access_log_table' => ENV['TREASURE_DATA_ACCESS_LOG_TABLE'], 'auto_create_table' => true }) end |
#load_yaml(path) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/td/logger/agent/rails/config.rb', line 118 def load_yaml(path) require 'yaml' require 'erb' src = File.read(path) yaml = ERB.new(src).result YAML.load(yaml) end |