Class: Chillfile::Config
- Inherits:
-
Object
- Object
- Chillfile::Config
- Defined in:
- lib/chillfile/config.rb
Constant Summary collapse
- CONFIG_FILE =
".chillfile"
- DEFAULTS =
{ "path" => ".", "couchdb_server" => "http://localhost:5984", "couchdb_database" => "chillfile", "couchdb_type_key" => "type" }.freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #with_path ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/chillfile/config.rb', line 12 def initialize( = {}) @config = {}.merge(DEFAULTS) if File.exists?(CONFIG_FILE) file = File.read(CONFIG_FILE) @config.merge(JSON.parse(file)) else #TODO use a logger #TODO only show the following line in debug loglevel #puts "no config file ('#{CONFIG_FILE}') found => using defaults" end @config.merge!() if @config.freeze end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/chillfile/config.rb', line 26 def [](key) if @config.has_key? key @config[key] else false end end |
#with_path ⇒ Object
34 35 36 37 38 |
# File 'lib/chillfile/config.rb', line 34 def with_path Dir.chdir self["path"] do yield end end |