Class: Chillfile::Config

Inherits:
Object
  • Object
show all
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

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(options = {})
  @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!(options) if options
  @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_pathObject



34
35
36
37
38
# File 'lib/chillfile/config.rb', line 34

def with_path
  Dir.chdir self["path"] do
    yield  
  end
end