Class: Biopsy::Settings
- Inherits:
-
Object
- Object
- Biopsy::Settings
- Includes:
- Singleton
- Defined in:
- lib/biopsy/settings.rb
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#gzip_intermediates ⇒ Object
Returns the value of attribute gzip_intermediates.
-
#keep_intermediates ⇒ Object
Returns the value of attribute keep_intermediates.
-
#objectives_dir ⇒ Object
Returns the value of attribute objectives_dir.
-
#objectives_subset ⇒ Object
Returns the value of attribute objectives_subset.
-
#sweep_cutoff ⇒ Object
Returns the value of attribute sweep_cutoff.
-
#target_dir ⇒ Object
Returns the value of attribute target_dir.
Instance Method Summary collapse
-
#all_settings ⇒ Object
Returns a hash of the settings.
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
-
#load(config_file) ⇒ Object
Loads settings from a YAML config file.
-
#save(config_file) ⇒ Object
Saves the settings to a YAML config file.
- #set_defaults ⇒ Object
-
#to_s ⇒ Object
Returns a YAML string representation of the settings.
Constructor Details
#initialize ⇒ Settings
Returns a new instance of Settings.
34 35 36 |
# File 'lib/biopsy/settings.rb', line 34 def initialize self.set_defaults end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
26 27 28 |
# File 'lib/biopsy/settings.rb', line 26 def base_dir @base_dir end |
#gzip_intermediates ⇒ Object
Returns the value of attribute gzip_intermediates.
32 33 34 |
# File 'lib/biopsy/settings.rb', line 32 def gzip_intermediates @gzip_intermediates end |
#keep_intermediates ⇒ Object
Returns the value of attribute keep_intermediates.
31 32 33 |
# File 'lib/biopsy/settings.rb', line 31 def keep_intermediates @keep_intermediates end |
#objectives_dir ⇒ Object
Returns the value of attribute objectives_dir.
28 29 30 |
# File 'lib/biopsy/settings.rb', line 28 def objectives_dir @objectives_dir end |
#objectives_subset ⇒ Object
Returns the value of attribute objectives_subset.
29 30 31 |
# File 'lib/biopsy/settings.rb', line 29 def objectives_subset @objectives_subset end |
#sweep_cutoff ⇒ Object
Returns the value of attribute sweep_cutoff.
30 31 32 |
# File 'lib/biopsy/settings.rb', line 30 def sweep_cutoff @sweep_cutoff end |
#target_dir ⇒ Object
Returns the value of attribute target_dir.
27 28 29 |
# File 'lib/biopsy/settings.rb', line 27 def target_dir @target_dir end |
Instance Method Details
#all_settings ⇒ Object
Returns a hash of the settings
77 78 79 80 81 82 83 84 |
# File 'lib/biopsy/settings.rb', line 77 def all_settings settings = {} instance_variables.each do |var| key = var[1..-1] settings[key] = self.instance_variable_get(var) end settings end |
#load(config_file) ⇒ Object
Loads settings from a YAML config file. If no file is specified, the default location (‘~/.biopsyrc’) is used. Settings loaded from the file are merged into any previously loaded settings.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/biopsy/settings.rb', line 54 def load config_file config_file ||= @config_file newsets = YAML::load_file(config_file) raise 'Config file was not valid YAML' if newsets == false newsets.deep_symbolize.each_pair do |key, value| varname = "@#{key.to_s}".to_sym unless self.instance_variables.include? varname raise SettingsError.new "Key #{key.to_s} in settings file is not valid" end self.instance_variable_set(varname, value) end end |
#save(config_file) ⇒ Object
Saves the settings to a YAML config file. If no file is specified, the default location (‘~/.biopsyrc’) is used.
69 70 71 72 73 74 |
# File 'lib/biopsy/settings.rb', line 69 def save config_file config_file ||= @config_file File.open(config_file, 'w') do |f| f.puts self.to_s end end |
#set_defaults ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/biopsy/settings.rb', line 38 def set_defaults # defaults @config_file = '~/.biopsyrc' @base_dir = ['.'] @target_dir = ['targets'] @objectives_dir = ['objectives'] @objectives_subset = nil @sweep_cutoff = 100 @keep_intermediates = false @gzip_intermediates = false end |
#to_s ⇒ Object
Returns a YAML string representation of the settings
87 88 89 |
# File 'lib/biopsy/settings.rb', line 87 def to_s all_settings.to_yaml end |