class SiteDiff::Config::Preset
Preset
helper.
Constants
- DIRECTORY
Directory in which presets live.
TODO: Move this outside “lib”.
Public Class Methods
all()
click to toggle source
Get all possible rules.
@return [Array]
All presets.
# File lib/sitediff/config/preset.rb, line 42 def self.all # Load and cache preset names. if @all.nil? @all = [] pattern = DIRECTORY + '*.yaml' Dir.glob(pattern) do |file| @all << File.basename(file, '.yaml') end end @all end
exist?(name, exception = false)
click to toggle source
Checks whether a preset exists.
# File lib/sitediff/config/preset.rb, line 57 def self.exist?(name, exception = false) result = File.exist? file(name) # Raise an exception, if required. if exception && !result raise Config::InvalidConfig, "Preset not found: #{name}" end result end
file(name)
click to toggle source
Returns the path to a preset file.
# File lib/sitediff/config/preset.rb, line 70 def self.file(name) DIRECTORY + "#{name}.yaml" end
read(name)
click to toggle source
Reads preset rules.
@param [String] preset
Presets
@return [Hash]
A hash containing the preset's rules.
# File lib/sitediff/config/preset.rb, line 25 def self.read(name) @cache = {} if @cache.nil? # Load and cache preset config. if @cache[name].nil? exist? name, true @cache[name] = Config.load_conf file(name) end @cache[name] end