Class: LogView::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/log_view/config.rb

Constant Summary collapse

CONFIG_FILE_NAME =
".log_view.yml"
CONFIG_SAMPLE =
%Q{
# This is a sample, please fill the options with your own configurations
# 
#
# project_name:
#   user: my_ssh_user
#   password: my_ssh_password
#   servers:
#     - some_name@some_server.com
#   files:
#     - "/log/dir/my_log_file.log"
#
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



22
23
24
25
26
27
28
29
# File 'lib/log_view/config.rb', line 22

def initialize
  path = Config.config_file_path
  File.open(path, "w") {|f| f.write(CONFIG_SAMPLE)} unless File.exists?(path)

  hash = YAML.load_file(path)
  @projects = hash ? hash.keys : []
  @config = OpenStruct.new(hash)
end

Instance Attribute Details

#projectsObject (readonly)

Returns the value of attribute projects.



20
21
22
# File 'lib/log_view/config.rb', line 20

def projects
  @projects
end

Class Method Details

.config_file_pathObject



36
37
38
# File 'lib/log_view/config.rb', line 36

def self.config_file_path
  File.join(Dir.home, CONFIG_FILE_NAME)
end

Instance Method Details

#load_project(name) ⇒ Object



31
32
33
34
# File 'lib/log_view/config.rb', line 31

def load_project name
  project_config = @config.send("#{name}")       
  OpenStruct.new(project_config)
end