class SiteDiff::Config::Creator
Public Class Methods
new(debug, before, after)
click to toggle source
Creates a Creator
object.
# File lib/sitediff/config/creator.rb, line 17 def initialize(debug, before, after) @config = nil @before = before @after = after @debug = debug end
Public Instance Methods
build_config(options)
click to toggle source
Build and populate the config object which is being created.
@param [String] options
One or more options.
# File lib/sitediff/config/creator.rb, line 55 def build_config(options) options = Config.stringify_keys options # Build config for "before" and "after". %w[before after].each do |tag| next unless (url = roots[tag]) @config[tag] = { 'url' => url } end # Build other settings. @config['settings'] = {} Config::ALLOWED_SETTINGS_KEYS.each do |key| @config['settings'][key] = options[key] end end
config_file()
click to toggle source
Returns the name of the config file.
# File lib/sitediff/config/creator.rb, line 102 def config_file @dir + Config::DEFAULT_FILENAME end
create(options)
click to toggle source
Build a config structure, return it.
# File lib/sitediff/config/creator.rb, line 34 def create(options) @config = {} # @callback = block @dir = Pathname.new(options[:directory]) # Setup instance vars @paths = Hash.new { |h, k| h[k] = Set.new } @cache = Cache.new(directory: @dir.to_s, create: true) @cache.write_tags << :before << :after build_config options write_config end
directory()
click to toggle source
Returns the name of the config directory.
# File lib/sitediff/config/creator.rb, line 96 def directory @dir end
make_gitignore(dir)
click to toggle source
Create a gitignore if we seem to be in git.
# File lib/sitediff/config/creator.rb, line 74 def make_gitignore(dir) # Check if we're in git unless dir.realpath.to_enum(:ascend).any? { |d| d.+('.git').exist? } return end dir.+('.gitignore').open('w') do |f| f.puts <<-GITIGNORE.gsub(/^\s+/, '') # Directories. diffs snapshot # Files. settings.yaml paths.txt failures.txt GITIGNORE end end
roots()
click to toggle source
Determine if we're dealing with one or two URLs.
# File lib/sitediff/config/creator.rb, line 26 def roots @roots = { 'after' => @after } @roots['before'] = @before || @after @roots end
write_config()
click to toggle source
Writes the built config into the config file. TODO: Exclude default params before writing.
# File lib/sitediff/config/creator.rb, line 109 def write_config make_gitignore(@dir) data = Config.remove_defaults(@config) config_file.open('w') { |f| f.puts data.to_yaml } end