Class: Figi::Config
- Inherits:
-
Object
- Object
- Figi::Config
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/figi/config.rb
Overview
Core class
Class Method Summary collapse
-
.from_json(path) ⇒ Object
Load config from json file.
-
.from_yaml(path) ⇒ Object
Load config from yaml file.
-
.load(config = {}, &block) ⇒ Object
Load config from hash.
Instance Method Summary collapse
-
#_figi_load(config = {}) {|@table| ... } ⇒ Object
Load config from hash, don’t use this directly.
-
#initialize ⇒ Config
constructor
Constructor.
-
#method_missing(mid, *args) ⇒ Object
Dispatch to Hashie::Mash.
Constructor Details
#initialize ⇒ Config
Constructor
62 63 64 |
# File 'lib/figi/config.rb', line 62 def initialize @table = Hashie::Mash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mid, *args) ⇒ Object
Dispatch to Hashie::Mash
81 82 83 |
# File 'lib/figi/config.rb', line 81 def method_missing(mid, *args) @table.send(mid, *args) end |
Class Method Details
.from_json(path) ⇒ Object
Load config from json file
28 29 30 |
# File 'lib/figi/config.rb', line 28 def from_json(path) instance._figi_load(JSON.parse(File.read(path))) end |
.from_yaml(path) ⇒ Object
Load config from yaml file
37 38 39 |
# File 'lib/figi/config.rb', line 37 def from_yaml(path) instance._figi_load(YAML.safe_load(File.read(path))) end |
.load(config = {}, &block) ⇒ Object
Load config from hash
55 56 57 |
# File 'lib/figi/config.rb', line 55 def load(config = {}, &block) instance._figi_load(config, &block) end |
Instance Method Details
#_figi_load(config = {}) {|@table| ... } ⇒ Object
Load config from hash, don’t use this directly
69 70 71 72 73 74 75 76 77 |
# File 'lib/figi/config.rb', line 69 def _figi_load(config = {}) if @table.nil? @table = Hashie::Mash.new(config) else @table.update(config) end yield @table if block_given? end |