Class: Carnivore::Config
- Inherits:
-
Object
- Object
- Carnivore::Config
- Extended by:
- Mixlib::Config
- Defined in:
- lib/carnivore/config.rb
Overview
Configuration helper
Class Method Summary (collapse)
-
+ (TrueClass, FalseClass) auto_symbolize(v = nil)
Set/get automatic symbolization of hash keys.
-
+ (self) build(path_or_hash)
Populates the configuration.
-
+ (self) configure(args)
Merge provided args into configuration.
-
+ (Object) get(*ary)
Fetch value from configuration.
Class Method Details
+ (TrueClass, FalseClass) auto_symbolize(v = nil)
Set/get automatic symbolization of hash keys
v |
Boolean value |
18 19 20 21 22 23 |
# File 'lib/carnivore/config.rb', line 18 def auto_symbolize(v=nil) unless(v.nil?) @hash_symbolizer = !!v end @hash_symbolizer.nil? ? false : @hash_symbolizer end |
+ (self) build(path_or_hash)
Populates the configuration
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/carnivore/config.rb', line 39 def build(path_or_hash) if(path_or_hash.is_a?(Hash)) conf = path_or_hash else if(File.exists?(path_or_hash.to_s)) conf = JSON.load(File.read(path_or_hash)) self.config_path = path_or_hash else raise "Failed to load configuration file: #{path_or_hash}" end end conf.each do |k,v| self.send(k, v) end self end |
+ (self) configure(args)
Merge provided args into configuration
29 30 31 32 33 |
# File 'lib/carnivore/config.rb', line 29 def configure(args) build(args[:config_path]) if args[:config_path] self.merge!(args) self end |
+ (Object) get(*ary)
Fetch value from configuration
66 67 68 69 70 71 72 73 |
# File 'lib/carnivore/config.rb', line 66 def get(*ary) value = Carnivore::Utils.retrieve(self, *ary) if(value.is_a?(Hash) && auto_symbolize) Smash.new(value) else value end end |