class Worklog::Configuration
Default is 3000.
@return [Integer] The port on which the web server runs.
@!attribute [rw] webserver_port
Possible values: :debug, :info, :warn, :error, :fatal
@return [Symbol] The logging level for the application.
@!attribute [rw] log_level
@return [String] The path where the application stores its data.
@!attribute [rw] storage_path
Configuration class for the application.
def self.load
-
(Configuration)
- the loaded configuration
def self.load file_path = File.join(Dir.home, '.worklog.yaml') 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'] else WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults." end config end
def default_storage_path?
-
(Boolean)
- true if the storage path is the default, false otherwise
def default_storage_path? @storage_path == File.join(Dir.home, '.worklog') end
def initialize(&block)
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) @webserver_port ||= 3000 end
def storage_path_exist?
-
(Boolean)
- true if the storage path exists, false otherwise
def storage_path_exist? File.exist?(@storage_path) end