Class: RFlow::Configuration::Setting

Inherits:
ConfigurationItem show all
Includes:
ActiveModel::Validations
Defined in:
lib/rflow/configuration/setting.rb

Constant Summary collapse

DEFAULTS =
{
  'rflow.application_name'           => 'rflow',
  'rflow.application_directory_path' => '.',
  'rflow.pid_directory_path'         => 'run', # relative to rflow.application_directory_path
  'rflow.log_directory_path'         => 'log', # relative to rflow.application_directory_path
  'rflow.log_file_path' => lambda {File.join(Setting['rflow.log_directory_path'], Setting['rflow.application_name'] + '.log')},
  'rflow.pid_file_path' => lambda {File.join(Setting['rflow.pid_directory_path'], Setting['rflow.application_name'] + '.pid')},
  'rflow.log_level' => 'INFO',
}
DIRECTORY_PATHS =
[
  'rflow.application_directory_path',
  'rflow.pid_directory_path',
  'rflow.log_directory_path',
]
FILE_PATHS =
[
  'rflow.log_file_path',
  'rflow.pid_file_path',
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](name) ⇒ Object



57
58
59
# File 'lib/rflow/configuration/setting.rb', line 57

def self.[](name)
  Setting.find(name).value rescue nil
end

Instance Method Details

#directory_path?Boolean

TODO: Think about making this a regex check to pull in other, externally-defined settings

Returns:

  • (Boolean)


41
42
43
# File 'lib/rflow/configuration/setting.rb', line 41

def directory_path?
  DIRECTORY_PATHS.include? self.name
end

#valid_directory_path?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/rflow/configuration/setting.rb', line 45

def valid_directory_path?
  unless File.directory? self.value
    errors.add :value, "setting '#{self.name}' is not a directory ('#{File.expand_path self.value}')"
  end
end

#valid_writable_path?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/rflow/configuration/setting.rb', line 51

def valid_writable_path?
  unless File.writable? self.value
    errors.add :value, "setting '#{self.name}' is not writable ('#{File.expand_path self.value}')"
  end
end