Class: Ablerc::Configuration
- Inherits:
-
Object
- Object
- Ablerc::Configuration
- Includes:
- Singleton
- Defined in:
- lib/ablerc/configuration.rb
Overview
Represents an rc file which consists of a series of key value pairs
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load(path) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #read_values {|_self| ... } ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
23 24 25 |
# File 'lib/ablerc/configuration.rb', line 23 def initialize @store ||= Hashie::Mash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
28 29 30 |
# File 'lib/ablerc/configuration.rb', line 28 def method_missing(method, *args, &block) store.send(method, *args, &block) end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
9 10 11 |
# File 'lib/ablerc/configuration.rb', line 9 def store @store end |
Class Method Details
.load(path) ⇒ Object
13 |
# File 'lib/ablerc/configuration.rb', line 13 def load(path); self.instance.load(path); end |
Instance Method Details
#load(path) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/ablerc/configuration.rb', line 33 def load(path) return unless File.exists? path self.instance_eval do File.read(File.(path)).each_line do |line| next if line =~ /^[?\s]*\#/ || line.blank? store.instance_eval("self."+line) end end end |
#read_values {|_self| ... } ⇒ Object
17 18 19 20 |
# File 'lib/ablerc/configuration.rb', line 17 def read_values(&rc_file) rc_file.call yield(self) end |