Class: Worklog::Configuration

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

Overview

Configuration class for the application.

Examples:

Example ~/.worklog.yaml

storage_path: /Users/username/.worklog
log_level: debug
timezone: 'America/Los_Angeles'
webserver_port: 4000

project:
  show_last: 3

github:
  api_key: 123abc
  username: sample-user

Defined Under Namespace

Classes: GithubConfig, ProjectConfig

Constant Summary collapse

CONFIGURATION_TEMPLATE =
ERB.new <<~YAML
  # Worklog Configuration File
  # This file contains configuration settings for Worklog.
  # You can modify the values below to customize your setup.
  # For more information, refer to the documentation.
  storage_path: <%= Dir.home %>/.worklog
  log_level: info
  timezone: 'America/Los_Angeles'
  webserver_port: 3000

  project:
    # Number of last projects to show in the project list
    show_last: 3

  github:
    # Your GitHub API key for accessing the GitHub API
    api_key: ""
    # Your GitHub username for finding assigned issues and PRs
    username: ""
YAML

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Configuration

Initialize configuration with optional block for setting attributes. If no block is given, default values are used.

Examples:

Configuration.new do |config|
  config.storage_path = '/custom/path'
  config.log_level = :debug
  config.timezone = 'America/Los_Angeles'
end


104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/configuration.rb', line 104

def initialize(&block)
  block.call(self) if block_given?

  # Set default values if not set
  @storage_path ||= File.join(Dir.home, '.worklog')
  @log_level = log_level || :info
  @log_level = @log_level.to_sym if @log_level.is_a?(String)
  @timezone ||= 'America/Los_Angeles'
  @timezone = TZInfo::Timezone.get(@timezone) if @timezone.is_a?(String)
  @webserver_port ||= 3000
  @project = ProjectConfig.new
  @github ||= GithubConfig.new
end

Instance Attribute Details

#githubConfiguration::GithubConfig

Returns Github related configuration.

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/configuration.rb', line 34

class Configuration
  attr_accessor :storage_path, :log_level, :timezone, :webserver_port, :project, :github

  # Configuration for projects
  # @!attribute [rw] show_last
  #   @return [Integer] Number of last projects to show in the project list.
  class ProjectConfig
    attr_accessor :show_last

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   ProjectConfig.new({'show_last' => 5})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  # Configuration for Github API access.
  # @!attribute [rw] api_key
  #   @return [String] The API key for Github access.
  # @!attribute [rw] username
  #   @return [String] The Github username.
  class GithubConfig
    attr_accessor :api_key, :username

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   GithubConfig.new({'api_key' => '123abc', 'username' => 'sample-user'})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  CONFIGURATION_TEMPLATE = ERB.new <<~YAML
    # Worklog Configuration File
    # This file contains configuration settings for Worklog.
    # You can modify the values below to customize your setup.
    # For more information, refer to the documentation.
    storage_path: <%= Dir.home %>/.worklog
    log_level: info
    timezone: 'America/Los_Angeles'
    webserver_port: 3000

    project:
      # Number of last projects to show in the project list
      show_last: 3

    github:
      # Your GitHub API key for accessing the GitHub API
      api_key: ""
      # Your GitHub username for finding assigned issues and PRs
      username: ""
  YAML

  # Initialize configuration with optional block for setting attributes.
  # If no block is given, default values are used.
  # @example
  #   Configuration.new do |config|
  #     config.storage_path = '/custom/path'
  #     config.log_level = :debug
  #     config.timezone = 'America/Los_Angeles'
  #   end
  def initialize(&block)
    block.call(self) if block_given?

    # Set default values if not set
    @storage_path ||= File.join(Dir.home, '.worklog')
    @log_level = log_level || :info
    @log_level = @log_level.to_sym if @log_level.is_a?(String)
    @timezone ||= 'America/Los_Angeles'
    @timezone = TZInfo::Timezone.get(@timezone) if @timezone.is_a?(String)
    @webserver_port ||= 3000
    @project = ProjectConfig.new
    @github ||= GithubConfig.new
  end

  # Load configuration from a YAML file in the user's home directory.
  # If the file does not exist, it will use default values.
  # @return [Configuration] the loaded configuration
  def self.load
    file_path = config_file_path
    config = Configuration.new
    if File.exist?(file_path)
      file_cfg = YAML.load_file(file_path)
      config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
      config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
      config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']

      config.project = ProjectConfig.new(file_cfg['project'])
      config.github = GithubConfig.new(file_cfg['github'])
    else
      WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
    end

    config
  end

  # Check if the storage path exists.
  # @return [Boolean] true if the storage path exists, false otherwise
  def storage_path_exist?
    File.exist?(@storage_path)
  end

  # Check if the storage path is the default path.
  # @return [Boolean] true if the storage path is the default, false otherwise
  def default_storage_path?
    @storage_path == File.join(Dir.home, '.worklog')
  end

  # Get the default configuration file path.
  # @return [String] the default configuration file path
  def self.config_file_path
    File.join(Dir.home, '.worklog.yaml')
  end
end

#log_levelSymbol

Possible values: :debug, :info, :warn, :error, :fatal

Returns:

  • (Symbol)

    The logging level for the application.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/configuration.rb', line 34

class Configuration
  attr_accessor :storage_path, :log_level, :timezone, :webserver_port, :project, :github

  # Configuration for projects
  # @!attribute [rw] show_last
  #   @return [Integer] Number of last projects to show in the project list.
  class ProjectConfig
    attr_accessor :show_last

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   ProjectConfig.new({'show_last' => 5})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  # Configuration for Github API access.
  # @!attribute [rw] api_key
  #   @return [String] The API key for Github access.
  # @!attribute [rw] username
  #   @return [String] The Github username.
  class GithubConfig
    attr_accessor :api_key, :username

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   GithubConfig.new({'api_key' => '123abc', 'username' => 'sample-user'})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  CONFIGURATION_TEMPLATE = ERB.new <<~YAML
    # Worklog Configuration File
    # This file contains configuration settings for Worklog.
    # You can modify the values below to customize your setup.
    # For more information, refer to the documentation.
    storage_path: <%= Dir.home %>/.worklog
    log_level: info
    timezone: 'America/Los_Angeles'
    webserver_port: 3000

    project:
      # Number of last projects to show in the project list
      show_last: 3

    github:
      # Your GitHub API key for accessing the GitHub API
      api_key: ""
      # Your GitHub username for finding assigned issues and PRs
      username: ""
  YAML

  # Initialize configuration with optional block for setting attributes.
  # If no block is given, default values are used.
  # @example
  #   Configuration.new do |config|
  #     config.storage_path = '/custom/path'
  #     config.log_level = :debug
  #     config.timezone = 'America/Los_Angeles'
  #   end
  def initialize(&block)
    block.call(self) if block_given?

    # Set default values if not set
    @storage_path ||= File.join(Dir.home, '.worklog')
    @log_level = log_level || :info
    @log_level = @log_level.to_sym if @log_level.is_a?(String)
    @timezone ||= 'America/Los_Angeles'
    @timezone = TZInfo::Timezone.get(@timezone) if @timezone.is_a?(String)
    @webserver_port ||= 3000
    @project = ProjectConfig.new
    @github ||= GithubConfig.new
  end

  # Load configuration from a YAML file in the user's home directory.
  # If the file does not exist, it will use default values.
  # @return [Configuration] the loaded configuration
  def self.load
    file_path = config_file_path
    config = Configuration.new
    if File.exist?(file_path)
      file_cfg = YAML.load_file(file_path)
      config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
      config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
      config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']

      config.project = ProjectConfig.new(file_cfg['project'])
      config.github = GithubConfig.new(file_cfg['github'])
    else
      WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
    end

    config
  end

  # Check if the storage path exists.
  # @return [Boolean] true if the storage path exists, false otherwise
  def storage_path_exist?
    File.exist?(@storage_path)
  end

  # Check if the storage path is the default path.
  # @return [Boolean] true if the storage path is the default, false otherwise
  def default_storage_path?
    @storage_path == File.join(Dir.home, '.worklog')
  end

  # Get the default configuration file path.
  # @return [String] the default configuration file path
  def self.config_file_path
    File.join(Dir.home, '.worklog.yaml')
  end
end

#projectConfiguration::ProjectConfig

Returns Project related configuration.

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/configuration.rb', line 34

class Configuration
  attr_accessor :storage_path, :log_level, :timezone, :webserver_port, :project, :github

  # Configuration for projects
  # @!attribute [rw] show_last
  #   @return [Integer] Number of last projects to show in the project list.
  class ProjectConfig
    attr_accessor :show_last

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   ProjectConfig.new({'show_last' => 5})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  # Configuration for Github API access.
  # @!attribute [rw] api_key
  #   @return [String] The API key for Github access.
  # @!attribute [rw] username
  #   @return [String] The Github username.
  class GithubConfig
    attr_accessor :api_key, :username

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   GithubConfig.new({'api_key' => '123abc', 'username' => 'sample-user'})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  CONFIGURATION_TEMPLATE = ERB.new <<~YAML
    # Worklog Configuration File
    # This file contains configuration settings for Worklog.
    # You can modify the values below to customize your setup.
    # For more information, refer to the documentation.
    storage_path: <%= Dir.home %>/.worklog
    log_level: info
    timezone: 'America/Los_Angeles'
    webserver_port: 3000

    project:
      # Number of last projects to show in the project list
      show_last: 3

    github:
      # Your GitHub API key for accessing the GitHub API
      api_key: ""
      # Your GitHub username for finding assigned issues and PRs
      username: ""
  YAML

  # Initialize configuration with optional block for setting attributes.
  # If no block is given, default values are used.
  # @example
  #   Configuration.new do |config|
  #     config.storage_path = '/custom/path'
  #     config.log_level = :debug
  #     config.timezone = 'America/Los_Angeles'
  #   end
  def initialize(&block)
    block.call(self) if block_given?

    # Set default values if not set
    @storage_path ||= File.join(Dir.home, '.worklog')
    @log_level = log_level || :info
    @log_level = @log_level.to_sym if @log_level.is_a?(String)
    @timezone ||= 'America/Los_Angeles'
    @timezone = TZInfo::Timezone.get(@timezone) if @timezone.is_a?(String)
    @webserver_port ||= 3000
    @project = ProjectConfig.new
    @github ||= GithubConfig.new
  end

  # Load configuration from a YAML file in the user's home directory.
  # If the file does not exist, it will use default values.
  # @return [Configuration] the loaded configuration
  def self.load
    file_path = config_file_path
    config = Configuration.new
    if File.exist?(file_path)
      file_cfg = YAML.load_file(file_path)
      config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
      config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
      config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']

      config.project = ProjectConfig.new(file_cfg['project'])
      config.github = GithubConfig.new(file_cfg['github'])
    else
      WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
    end

    config
  end

  # Check if the storage path exists.
  # @return [Boolean] true if the storage path exists, false otherwise
  def storage_path_exist?
    File.exist?(@storage_path)
  end

  # Check if the storage path is the default path.
  # @return [Boolean] true if the storage path is the default, false otherwise
  def default_storage_path?
    @storage_path == File.join(Dir.home, '.worklog')
  end

  # Get the default configuration file path.
  # @return [String] the default configuration file path
  def self.config_file_path
    File.join(Dir.home, '.worklog.yaml')
  end
end

#storage_pathString

Returns The path where the application stores its data.

Returns:

  • (String)

    The path where the application stores its data.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/configuration.rb', line 34

class Configuration
  attr_accessor :storage_path, :log_level, :timezone, :webserver_port, :project, :github

  # Configuration for projects
  # @!attribute [rw] show_last
  #   @return [Integer] Number of last projects to show in the project list.
  class ProjectConfig
    attr_accessor :show_last

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   ProjectConfig.new({'show_last' => 5})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  # Configuration for Github API access.
  # @!attribute [rw] api_key
  #   @return [String] The API key for Github access.
  # @!attribute [rw] username
  #   @return [String] The Github username.
  class GithubConfig
    attr_accessor :api_key, :username

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   GithubConfig.new({'api_key' => '123abc', 'username' => 'sample-user'})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  CONFIGURATION_TEMPLATE = ERB.new <<~YAML
    # Worklog Configuration File
    # This file contains configuration settings for Worklog.
    # You can modify the values below to customize your setup.
    # For more information, refer to the documentation.
    storage_path: <%= Dir.home %>/.worklog
    log_level: info
    timezone: 'America/Los_Angeles'
    webserver_port: 3000

    project:
      # Number of last projects to show in the project list
      show_last: 3

    github:
      # Your GitHub API key for accessing the GitHub API
      api_key: ""
      # Your GitHub username for finding assigned issues and PRs
      username: ""
  YAML

  # Initialize configuration with optional block for setting attributes.
  # If no block is given, default values are used.
  # @example
  #   Configuration.new do |config|
  #     config.storage_path = '/custom/path'
  #     config.log_level = :debug
  #     config.timezone = 'America/Los_Angeles'
  #   end
  def initialize(&block)
    block.call(self) if block_given?

    # Set default values if not set
    @storage_path ||= File.join(Dir.home, '.worklog')
    @log_level = log_level || :info
    @log_level = @log_level.to_sym if @log_level.is_a?(String)
    @timezone ||= 'America/Los_Angeles'
    @timezone = TZInfo::Timezone.get(@timezone) if @timezone.is_a?(String)
    @webserver_port ||= 3000
    @project = ProjectConfig.new
    @github ||= GithubConfig.new
  end

  # Load configuration from a YAML file in the user's home directory.
  # If the file does not exist, it will use default values.
  # @return [Configuration] the loaded configuration
  def self.load
    file_path = config_file_path
    config = Configuration.new
    if File.exist?(file_path)
      file_cfg = YAML.load_file(file_path)
      config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
      config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
      config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']

      config.project = ProjectConfig.new(file_cfg['project'])
      config.github = GithubConfig.new(file_cfg['github'])
    else
      WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
    end

    config
  end

  # Check if the storage path exists.
  # @return [Boolean] true if the storage path exists, false otherwise
  def storage_path_exist?
    File.exist?(@storage_path)
  end

  # Check if the storage path is the default path.
  # @return [Boolean] true if the storage path is the default, false otherwise
  def default_storage_path?
    @storage_path == File.join(Dir.home, '.worklog')
  end

  # Get the default configuration file path.
  # @return [String] the default configuration file path
  def self.config_file_path
    File.join(Dir.home, '.worklog.yaml')
  end
end

#timezoneObject

Returns the value of attribute timezone.



35
36
37
# File 'lib/configuration.rb', line 35

def timezone
  @timezone
end

#webserver_portInteger

Default is 3000.

Returns:

  • (Integer)

    The port on which the web server runs.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/configuration.rb', line 34

class Configuration
  attr_accessor :storage_path, :log_level, :timezone, :webserver_port, :project, :github

  # Configuration for projects
  # @!attribute [rw] show_last
  #   @return [Integer] Number of last projects to show in the project list.
  class ProjectConfig
    attr_accessor :show_last

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   ProjectConfig.new({'show_last' => 5})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  # Configuration for Github API access.
  # @!attribute [rw] api_key
  #   @return [String] The API key for Github access.
  # @!attribute [rw] username
  #   @return [String] The Github username.
  class GithubConfig
    attr_accessor :api_key, :username

    # Initialize with default values, parameters can be overridden via hash
    # @example
    #   GithubConfig.new({'api_key' => '123abc', 'username' => 'sample-user'})
    def initialize(params = {})
      return if params.nil?

      params.each do |key, value|
        instance_variable_set("@#{key}", value) if respond_to?("#{key}=")
      end
    end
  end

  CONFIGURATION_TEMPLATE = ERB.new <<~YAML
    # Worklog Configuration File
    # This file contains configuration settings for Worklog.
    # You can modify the values below to customize your setup.
    # For more information, refer to the documentation.
    storage_path: <%= Dir.home %>/.worklog
    log_level: info
    timezone: 'America/Los_Angeles'
    webserver_port: 3000

    project:
      # Number of last projects to show in the project list
      show_last: 3

    github:
      # Your GitHub API key for accessing the GitHub API
      api_key: ""
      # Your GitHub username for finding assigned issues and PRs
      username: ""
  YAML

  # Initialize configuration with optional block for setting attributes.
  # If no block is given, default values are used.
  # @example
  #   Configuration.new do |config|
  #     config.storage_path = '/custom/path'
  #     config.log_level = :debug
  #     config.timezone = 'America/Los_Angeles'
  #   end
  def initialize(&block)
    block.call(self) if block_given?

    # Set default values if not set
    @storage_path ||= File.join(Dir.home, '.worklog')
    @log_level = log_level || :info
    @log_level = @log_level.to_sym if @log_level.is_a?(String)
    @timezone ||= 'America/Los_Angeles'
    @timezone = TZInfo::Timezone.get(@timezone) if @timezone.is_a?(String)
    @webserver_port ||= 3000
    @project = ProjectConfig.new
    @github ||= GithubConfig.new
  end

  # Load configuration from a YAML file in the user's home directory.
  # If the file does not exist, it will use default values.
  # @return [Configuration] the loaded configuration
  def self.load
    file_path = config_file_path
    config = Configuration.new
    if File.exist?(file_path)
      file_cfg = YAML.load_file(file_path)
      config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
      config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
      config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']

      config.project = ProjectConfig.new(file_cfg['project'])
      config.github = GithubConfig.new(file_cfg['github'])
    else
      WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
    end

    config
  end

  # Check if the storage path exists.
  # @return [Boolean] true if the storage path exists, false otherwise
  def storage_path_exist?
    File.exist?(@storage_path)
  end

  # Check if the storage path is the default path.
  # @return [Boolean] true if the storage path is the default, false otherwise
  def default_storage_path?
    @storage_path == File.join(Dir.home, '.worklog')
  end

  # Get the default configuration file path.
  # @return [String] the default configuration file path
  def self.config_file_path
    File.join(Dir.home, '.worklog.yaml')
  end
end

Class Method Details

.config_file_pathString

Get the default configuration file path.

Returns:

  • (String)

    the default configuration file path



153
154
155
# File 'lib/configuration.rb', line 153

def self.config_file_path
  File.join(Dir.home, '.worklog.yaml')
end

.loadConfiguration

Load configuration from a YAML file in the user’s home directory. If the file does not exist, it will use default values.

Returns:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/configuration.rb', line 121

def self.load
  file_path = config_file_path
  config = Configuration.new
  if File.exist?(file_path)
    file_cfg = YAML.load_file(file_path)
    config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
    config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
    config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']

    config.project = ProjectConfig.new(file_cfg['project'])
    config.github = GithubConfig.new(file_cfg['github'])
  else
    WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
  end

  config
end

Instance Method Details

#default_storage_path?Boolean

Check if the storage path is the default path.

Returns:

  • (Boolean)

    true if the storage path is the default, false otherwise



147
148
149
# File 'lib/configuration.rb', line 147

def default_storage_path?
  @storage_path == File.join(Dir.home, '.worklog')
end

#storage_path_exist?Boolean

Check if the storage path exists.

Returns:

  • (Boolean)

    true if the storage path exists, false otherwise



141
142
143
# File 'lib/configuration.rb', line 141

def storage_path_exist?
  File.exist?(@storage_path)
end