lib/rflow/configuration/setting.rb in rflow-0.0.5 vs lib/rflow/configuration/setting.rb in rflow-1.0.0a1

- old
+ new

@@ -6,23 +6,24 @@ class Setting < ConfigDB class SettingInvalid < StandardError; end include ActiveModel::Validations - set_primary_key :name + self.primary_key = 'name' + attr_accessible :name, :value - + DEFAULTS = { 'rflow.application_name' => 'rflow', - + 'rflow.application_directory_path' => '.', 'rflow.pid_directory_path' => 'run', #lambda {File.join(Setting['rflow.application_directory_path'], 'run')}, 'rflow.log_directory_path' => 'log', #lambda {File.join(Setting['rflow.application_directory_path'], 'log')}, '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', @@ -39,29 +40,29 @@ #application directory path context for subdirectories #validate :valid_directory_path, :if => :directory_path? #validate :valid_writable_path, :if => :directory_path? # TODO: Think about making this a regex check to pull in other, - # externally-defined settings + # externally-defined settings def directory_path? DIRECTORY_PATHS.include? self.name end 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 - + 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 def self.[](setting_name) Setting.find(setting_name).value rescue nil end - + end end end