Class: Biopsy::Settings

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/biopsy/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

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_dirObject

Returns the value of attribute base_dir.



26
27
28
# File 'lib/biopsy/settings.rb', line 26

def base_dir
  @base_dir
end

#gzip_intermediatesObject

Returns the value of attribute gzip_intermediates.



32
33
34
# File 'lib/biopsy/settings.rb', line 32

def gzip_intermediates
  @gzip_intermediates
end

#keep_intermediatesObject

Returns the value of attribute keep_intermediates.



31
32
33
# File 'lib/biopsy/settings.rb', line 31

def keep_intermediates
  @keep_intermediates
end

#objectives_dirObject

Returns the value of attribute objectives_dir.



28
29
30
# File 'lib/biopsy/settings.rb', line 28

def objectives_dir
  @objectives_dir
end

#objectives_subsetObject

Returns the value of attribute objectives_subset.



29
30
31
# File 'lib/biopsy/settings.rb', line 29

def objectives_subset
  @objectives_subset
end

#sweep_cutoffObject

Returns the value of attribute sweep_cutoff.



30
31
32
# File 'lib/biopsy/settings.rb', line 30

def sweep_cutoff
  @sweep_cutoff
end

#target_dirObject

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_settingsObject

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_defaultsObject



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_sObject

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