class Cukedep::Config

Re-open the class for further customisation Configuration object for the Cukedep application.

Public Class Methods

default() click to toggle source

Factory method. Build a config object with default settings.

# File lib/cukedep/config.rb, line 28
def self.default
  instance = Config.new(
    'UTF-8',
    nil,
    FileMetaData.new('feature2id.csv'),
    FileMetaData.new('feature2id.csv'),
    FileMetaData.new('dependencies.dot'),
    'cukedep.rake',
    []
  )

  file_action_attrs.each do |attr|
    instance[attr] = empty_action_triplet
  end

  return instance
end
empty_action_triplet() click to toggle source

Return Hash config for a no-op action triplet.

# File lib/cukedep/config.rb, line 72
def self.empty_action_triplet
  {
    save_patterns: [],
    save_subdir: '',
    delete_patterns: [],
    delete_subdir: '',
    copy_patterns: [],
    copy_subdir: ''
  }
end
file_action_attrs() click to toggle source

Purpose: get the list of attributes referencing a file action triplet.

# File lib/cukedep/config.rb, line 62
def self.file_action_attrs
  return %I[
    before_all_f_actions
    before_each_f_actions
    after_each_f_actions
    after_all_f_actions
  ]
end
load_cfg(filename) click to toggle source

Read the YAML file with specified name from the current working directory. If that file does not exist, then return an instance with default values.

# File lib/cukedep/config.rb, line 48
def self.load_cfg(filename)
  # TODO: validation
  instance = File.exist?(filename) ? YAML.load_file(filename) : default

  return instance
end

Public Instance Methods

write(filename) click to toggle source

Save the Config object to a YAML file.

# File lib/cukedep/config.rb, line 56
def write(filename)
  File.open(filename, 'w') { |f| YAML.dump(self, f) }
end