class Prodder::Config

Constants

LintError
PathError

Attributes

workspace[RW]

Public Class Methods

example_contents() click to toggle source
# File lib/prodder/config.rb, line 75
    def self.example_contents
      <<-EOF.gsub(/^      /, '')
      blog:
        structure_file: db/structure.sql
        seed_file: db/seeds.sql
        quality_check_file: db/quality_checks.sql
        git:
          origin: git@github.com:your/repo.git
          author: prodder <prodder@example.com>
        db:
          name: database_name
          host: database.server.example.com
          user: username
          password: password
          tables:
            - posts
            - authors
      EOF
    end
new(project_definitions) click to toggle source
# File lib/prodder/config.rb, line 19
def initialize(project_definitions)
  @config = project_definitions
end

Public Instance Methods

assert_in_path(*cmds) click to toggle source
# File lib/prodder/config.rb, line 23
def assert_in_path(*cmds)
  path = ENV['PATH'].split(File::PATH_SEPARATOR)
  cmds.each do |cmd|
    raise PathError.new(cmd) unless path.find { |dir| File.exist? File.join(dir, cmd) }
  end
end
lint() click to toggle source
# File lib/prodder/config.rb, line 30
def lint
  assert_in_path 'pg_dump'
  assert_in_path 'git'

  required = {
    'structure_file'     => [],
    'seed_file'          => [],
    'db'                 => %w[name host user tables],
    'git'                => %w[origin author]
  }

  @config.each_with_object([]) do |(project, defn), errors|
    required.each do |top, inner|
      if !defn.key?(top)
        errors << "Missing required configuration key: #{project}/#{top}"
      else
        errors.concat inner.reject { |key| defn[top].key?(key) }.map { |key|
          "Missing required configuration key: #{project}/#{top}/#{key}"
        }
      end
    end
  end
end
lint!() click to toggle source
# File lib/prodder/config.rb, line 54
def lint!
  lint.tap { |errors| raise LintError.new(errors) if errors.any? }
end
projects() click to toggle source
# File lib/prodder/config.rb, line 58
def projects
  @projects ||= @config.map { |name, defn| Project.new(name, File.join(workspace, name), defn) }
end
select_projects(names) { |unmatched| ... } click to toggle source
# File lib/prodder/config.rb, line 62
def select_projects(names)
  return projects if names.empty?

  matches = projects.select { |project| names.include?(project.name) }

  if matches.size != names.size
    unmatched = names - matches.map(&:name)
    yield unmatched if block_given?
  end

  matches
end