Class: WorkLoggerConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/konkit_worklogger/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worklogger_path) ⇒ WorkLoggerConfiguration

Returns a new instance of WorkLoggerConfiguration.



7
8
9
# File 'lib/konkit_worklogger/configuration.rb', line 7

def initialize(worklogger_path)
  @worklogger_path = worklogger_path
end

Instance Attribute Details

#worklogger_pathObject (readonly)

Returns the value of attribute worklogger_path.



5
6
7
# File 'lib/konkit_worklogger/configuration.rb', line 5

def worklogger_path
  @worklogger_path
end

Class Method Details

.loadObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/konkit_worklogger/configuration.rb', line 11

def self.load
  config_path = '%s/.konkit_worklogger/config.yml' % Dir.home

  conf = if File.file?(config_path)
           config_file_content = IO.read(config_path)
           config = YAML.safe_load(config_file_content)

           worklogger_path = config['path']

           WorkLoggerConfiguration.new(worklogger_path)
         else
           default_entries_path = '%s/.konkit_worklogger/timeentries' % Dir.home

           unless File.directory?('%s/.konkit_worklogger/' % Dir.home)
             FileUtils.mkdir_p('%s/.konkit_worklogger/' % Dir.home)
           end

           File.open(@config_path, 'w') { |file| file.write({ 'path' => default_entries_path }.to_yaml) }
           WorkLoggerConfiguration.new(default_entries_path)
         end

  FileUtils.mkdir_p(conf.worklogger_path) unless File.directory?(conf.worklogger_path)

  conf
end