Class: Howdy::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/howdy/config.rb

Overview

Howdy configuration. Configuration file points to $HOME/.howdy by default

Constant Summary collapse

TEMPLATE_PATH =

Path of default configuration file It’s copied to user directory if config file doesn’t exist.

File.join(File.dirname(__FILE__), 'templates', 'howdy')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = self.class.config_path) ⇒ Config

Returns a new instance of Config.



15
16
17
# File 'lib/howdy/config.rb', line 15

def	initialize(file = self.class.config_path)
	@file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/howdy/config.rb', line 9

def file
  @file
end

Class Method Details

.config_filenameObject

filename of configuration file

example: .howdy


52
53
54
# File 'lib/howdy/config.rb', line 52

def	self.config_filename
  @config_filename ||= ".howdy".freeze
end

.config_pathObject

path of configuration file

example: /home/stella/.howdy


40
41
42
# File 'lib/howdy/config.rb', line 40

def	self.config_path
  @config_path ||= File.join(root_config_path, config_filename) 
end

.root_config_pathObject

root directory of config file

example: /home/stella


46
47
48
# File 'lib/howdy/config.rb', line 46

def	self.root_config_path
  @root_config_path ||= (ENV['HOME'] || '') 
end

Instance Method Details

#parseObject

Parse file and associate options to self

example:
  howdy.conf:
    default_dictionary = dictionary.com
    verbose = true

  c = Config.new('howdy.conf')
  c.parse
  c.inspect
    { :default_dictionary => 'dictionary.com', :verbose => 'true' }


29
30
31
32
33
34
35
36
# File 'lib/howdy/config.rb', line 29

def	parse
	readlines.each do |line|
		next if line =~ /\s*#/
		key, value = line.split('=', 2).map! { |arg| arg.strip }
      self[key.to_sym] = value
	end
    self
end