Class: Ragnar::Config
- Inherits:
-
Object
- Object
- Ragnar::Config
- Defined in:
- lib/ragnar.rb
Overview
Set all your configuration options.
log_conf = YAML.load_file(Rails.root.join('config/gelf_logger.yml'))[Rails.env]
Ragnar::Config.configure do |c|
c.env = 'environment'
c.logger = logger_instance
c.host = 'localhost'
c.port = 5672
end
If no logger is defined, the default will be set to Logger and output will be directed to STDOUT
Class Method Summary collapse
- .config ⇒ Object
- .configure {|_self| ... } ⇒ Object
- .method_missing(sym, *args, &blk) ⇒ Object
- .restore_defaults! ⇒ Object
- .valid_key?(key) ⇒ Boolean
Class Method Details
.config ⇒ Object
34 35 36 |
# File 'lib/ragnar.rb', line 34 def self.config @config.instance_variable_get(:@table) end |
.configure {|_self| ... } ⇒ Object
30 31 32 |
# File 'lib/ragnar.rb', line 30 def self.configure yield self end |
.method_missing(sym, *args, &blk) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ragnar.rb', line 54 def self.method_missing(sym, *args, &blk) case when sym.to_s =~ /(.+)=$/ && valid_key?($1.to_sym) then @config.send(sym, *args, &blk) when @config.respond_to?(sym) then @config.send(sym, *args, &blk) else super end end |
.restore_defaults! ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/ragnar.rb', line 45 def self.restore_defaults! self.configure do |c| c.logger = Logger.new(STDOUT) c.env = :development c.host = 'localhost' c.port = 5672 end end |
.valid_key?(key) ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/ragnar.rb', line 38 def self.valid_key?(key) [ :logger, :env, :host, :port ].include?(key) end |