Class: Figgy
- Inherits:
-
Object
- Object
- Figgy
- Defined in:
- lib/figgy.rb,
lib/figgy/hash.rb,
lib/figgy/store.rb,
lib/figgy/finder.rb,
lib/figgy/version.rb,
lib/figgy/configuration.rb
Overview
An instance of Figgy is the object used to provide access to your configuration files. This does very little but recognize missing methods and go look them up as a configuration key.
To create a new instance, you probably want to use Figgy.build
:
MyConfig = Figgy.build do |config|
config.root = '/path/to/my/configs'
end
MyConfig.foo. #=> read from /path/to/my/configs/foo.yml
This should maybe be a BasicObject or similar, to provide as many available configuration keys as possible. Maybe.
Defined Under Namespace
Classes: Configuration, Finder, Hash, Store
Constant Summary collapse
- FileNotFound =
Class.new(StandardError)
- VERSION =
"1.3.0"
Class Method Summary collapse
-
.build {|Figgy::Configuration| ... } ⇒ Figgy
A Figgy instance using the configuration.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(config) ⇒ Figgy
constructor
A new instance of Figgy.
- #inspect ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #respond_to?(m) ⇒ Boolean
- #respond_to_missing?(m) ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Figgy
Returns a new instance of Figgy.
35 36 37 38 39 40 41 42 43 |
# File 'lib/figgy.rb', line 35 def initialize(config) @config = config @finder = Finder.new(config) @store = Store.new(@finder, @config) if @config.preload? @finder.all_key_names.each { |key| @store.get(key) } end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
49 50 51 |
# File 'lib/figgy.rb', line 49 def method_missing(m, *args, &block) @store.get(m) end |
Class Method Details
.build {|Figgy::Configuration| ... } ⇒ Figgy
Returns a Figgy instance using the configuration.
29 30 31 32 33 |
# File 'lib/figgy.rb', line 29 def self.build(&block) config = Configuration.new block.call(config) new(config) end |
Instance Method Details
#[](key) ⇒ Object
45 46 47 |
# File 'lib/figgy.rb', line 45 def [](key) @store.get(key) end |
#inspect ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/figgy.rb', line 63 def inspect if @store.size > 0 key_names = @store.keys.sort "#<Figgy (#{@store.size} keys): #{key_names.join(' ')}>" else "#<Figgy (empty)>" end end |
#respond_to?(m) ⇒ Boolean
53 54 55 |
# File 'lib/figgy.rb', line 53 def respond_to?(m, *) super || respond_to_missing?(m) end |
#respond_to_missing?(m) ⇒ Boolean
57 58 59 60 61 |
# File 'lib/figgy.rb', line 57 def respond_to_missing?(m, *) @store.get(m) != nil rescue Figgy::FileNotFound false end |