Class: Rnotifier::Config

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

Constant Summary collapse

DEFAULT =
{
  :api_host     => 'http://api.rnotifier.com',
  :api_version  => 'v1', 
  :exception_path  => 'exception',
  :event_path   => 'event',
  :ignore_env   => ['development', 'test'],
  :http_open_timeout => 2,
  :http_read_timeout => 4
}
CLIENT =
"RRG:#{Rnotifier::VERSION}"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_hostObject

Returns the value of attribute api_host.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def api_host
  @api_host
end

.api_keyObject

Returns the value of attribute api_key.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def api_key
  @api_key
end

.app_envObject

Returns the value of attribute app_env.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def app_env
  @app_env
end

.capture_codeObject

Returns the value of attribute capture_code.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def capture_code
  @capture_code
end

.current_envObject

Returns the value of attribute current_env.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def current_env
  @current_env
end

.environmentsObject

Returns the value of attribute environments.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def environments
  @environments
end

.event_pathObject

Returns the value of attribute event_path.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def event_path
  @event_path
end

.exception_pathObject

Returns the value of attribute exception_path.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def exception_path
  @exception_path
end

.ignore_botsObject

Returns the value of attribute ignore_bots.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def ignore_bots
  @ignore_bots
end

.ignore_exceptionsObject

Returns the value of attribute ignore_exceptions.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def ignore_exceptions
  @ignore_exceptions
end

.validObject

Returns the value of attribute valid.



16
17
18
# File 'lib/rnotifier/config.rb', line 16

def valid
  @valid
end

Class Method Details

.[](val) ⇒ Object



19
20
21
# File 'lib/rnotifier/config.rb', line 19

def [](val)
  DEFAULT[val]
end

.app_rootObject



82
83
84
# File 'lib/rnotifier/config.rb', line 82

def app_root
  (defined?(Rails) && Rails.respond_to?(:root)) ? Rails.root.to_s : Dir.pwd
end

.get_app_envObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rnotifier/config.rb', line 63

def get_app_env
  {
    :env => self.current_env,
    :pid => $$,
    :host => (Socket.gethostname rescue ''),
    :user_name => ENV['USER'] || ENV['USERNAME'],
    :program_name => $PROGRAM_NAME,
    :app_root => self.app_root,
    :language => {
      :name => 'ruby',
      :version => "#{(RUBY_VERSION rescue '')}-p#{(RUBY_PATCHLEVEL rescue '')}",
      :platform =>  (RUBY_PLATFORM rescue ''),
      :ruby_path => Gem.ruby,
      :gem_path => Gem.path
    },
    :timezone => (Time.now.zone rescue nil)
  }
end

.initObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rnotifier/config.rb', line 23

def init
  Rlogger.init

  self.valid = false
  self.current_env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development' 
  self.environments ||= []

  if self.environments.is_a?(String) || self.environments.is_a?(Symbol)
    self.environments = self.environments.to_s.split(',').collect(&:strip)
  end

  #Return if config environments not include current env
  return if !self.environments.empty? && !self.environments.include?(self.current_env)

  #Check for ignore env
  if DEFAULT[:ignore_env].include?(self.current_env) && !self.environments.include?(self.current_env) 
    return
  end

  if self.api_key.nil? and !ENV['RNOTIFIER_API_KEY'].nil?
    self.api_key = ENV['RNOTIFIER_API_KEY']
  end

  return if self.api_key.to_s.length == 0

  self.api_host ||= DEFAULT[:api_host]
  self.exception_path = '/' + [DEFAULT[:api_version], DEFAULT[:exception_path]].join('/')
  self.app_env = get_app_env

  self.ignore_exceptions = self.ignore_exceptions.split(',').map(&:strip) if self.ignore_exceptions.is_a?(String)
  self.ignore_bots = self.ignore_bots.split(',').map(&:strip) if self.ignore_bots.is_a?(String)
  
  self.event_path = '/' + [DEFAULT[:api_version], DEFAULT[:event_path]].join('/')
  self.valid = true 
end

.valid?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/rnotifier/config.rb', line 59

def valid?
  self.valid
end