Class: Excepty::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/excepty/settings.rb

Constant Summary collapse

PROTOCOL_VERSION =
"1"

Class Method Summary collapse

Class Method Details

.can_catch_exceptions?Boolean



79
80
81
82
# File 'lib/excepty/settings.rb', line 79

def self.can_catch_exceptions?
  return true if EXCEPTY_IN_TESTING_MODE
  return @config['enabled'] || true
end

.configObject



75
76
77
# File 'lib/excepty/settings.rb', line 75

def self.config
  @config
end

.configure_with_file(config_yml_file) ⇒ Object

Configure Settings through yaml file



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/excepty/settings.rb', line 42

def self.configure_with_file( config_yml_file )
  #begin
  if config_yml_file.blank? || !File.file?( config_yml_file )
    #TODO what can I do or say?
    Excepty::Manager.logga "BLANCO" if EXCEPTY_IN_TESTING_MODE
    return
  end
  
  Excepty::Manager.logga "Excepty - Settings - 5" if EXCEPTY_IN_TESTING_MODE
  #begin
  enviroment = ENV['RAILS_ENV'] || ENV['RACK_ENV']
  config_yml = YAML::load( IO.read( config_yml_file ) )
  #config_yml = YAML.load( ERB.new( File.new( config_yml_file ).read ).result )
  config_yml_by_env = config_yml[enviroment] || {}
  begin
  rescue Errno::ENOENT
    log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
  rescue Psych::SyntaxError
    log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
  end
  
  #begin
  #@config.each { |k,v| @config[k.to_sym] = config_yml_by_env[k.to_sym] || config_yml[k.to_sym] || v if @valid_config_keys.include? k.to_sym }
  @config.each do |k,v|
    @config[k.to_sym] = config_yml_by_env[k.to_s] || config_yml[k.to_s] || v if @valid_config_keys.include? k.to_sym
  end
  Excepty::Manager.logga "@config: #{@config.to_json}" if EXCEPTY_IN_TESTING_MODE
  begin # <= lele
  rescue Exception => e
    log(:warning, "YAML Settings error in load yml file."); return
  end
end

.get_structObject



84
85
86
87
88
89
90
91
92
# File 'lib/excepty/settings.rb', line 84

def self.get_struct
  obj = {}
  begin obj['app_name'] = @config[:app_name]; rescue Exception => e; end
  begin obj['key'] = @config[:key]; rescue Exception => e; end
  begin obj['webapp_name_by_env'] = ENV["APP_NAME"]; rescue Exception => e; end
  begin obj['webapp_name'] = Rails.application.class.parent_name; rescue Exception => e; end
  begin obj['webapp_name_class'] = Rails.application.class.to_s; rescue Exception => e; end
  return obj
end