Class: Figgy

Inherits:
Object
  • Object
show all
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.bar #=> 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

FileNotFound =
Class.new(StandardError)
VERSION =
"1.1.0"

Class Method Summary collapse

Instance Method Summary collapse

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

Yields:

Returns:

  • (Figgy)

    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

#inspectObject



59
60
61
62
63
64
65
66
# File 'lib/figgy.rb', line 59

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_missing?(m) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/figgy.rb', line 53

def respond_to_missing?(m, *)
  @store.get(m) != nil
rescue Figgy::FileNotFound
  false
end