Module: Noteman::Config

Included in:
Display, Note, NoteManager
Defined in:
lib/noteman/config.rb

Constant Summary collapse

CONFIG_NAME =
".notemanrc"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/noteman/config.rb', line 8

def config
  @config
end

Instance Method Details

#home_configObject



31
32
33
34
35
36
37
# File 'lib/noteman/config.rb', line 31

def home_config
  if Dir.respond_to?('home')
    File.join(Dir.home, CONFIG_NAME)
  else
    File.join(File.expand_path("~"), CONFIG_NAME)
  end
end

#read_from_fileObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/noteman/config.rb', line 39

def read_from_file
  c = {}
  dir = Dir.pwd
  while(dir != '/')
    if File.exists? File.join(dir, CONFIG_NAME)
      c = YAML.load_file(File.join(dir, CONFIG_NAME)).deep_merge!(c)
    end
    dir = File.dirname(dir)
  end
  if c.empty? && File.exists?(home_config)
    c = YAML.load_file(home_config)
  end
  c
end