Sha256: 6459269b26fea53005d71457bc959c1d7ded41a6fb1e17247715e3d37c7d5c2e

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

require 'pathname'
require 'yaml'

require_relative 'gemfile_selector'

module SchemaDev
  module Travis
    extend self

    TRAVIS_FILE = ".travis.yml"

    def build(config)
      env = []
      env << 'POSTGRESQL_DB_USER=postgres' if config.dbms.include? :postgresql
      env << 'MYSQL_DB_USER=travis' if config.dbms.include? :mysql
      env = env.join(' ')
      gemfiles = config.matrix.map{|entry| GemfileSelector.gemfile(entry.slice(:rails, :db)).to_s}.uniq
      exclude = config.matrix(excluded: :only).map { |entry| {}.tap {|ex|
        ex["rvm"] = entry[:ruby]
        ex["gemfile"] = GemfileSelector.gemfile(entry.slice(:rails, :db)).to_s
        ex["env"] = env if config.dbms.any?
      }}.reject{|ex| not gemfiles.include? ex["gemfile"]}

      {}.tap { |travis|
        travis["sudo"] = false
        travis["rvm"] = config.ruby.sort
        travis["gemfile"] = gemfiles.sort
        if config.dbms.any?
          travis["env"] = env
          travis["before_script"] = 'bundle exec rake create_databases'
          travis["after_script"] = 'bundle exec rake drop_databases'
        end
        travis["script"] = "bundle exec rake travis"
        travis["notifications"] = { "email" => config.notify } if config.notify.any?
        travis["matrix"] = { "exclude" => exclude.sort_by{|ex| [ex["rvm"], ex["gemfile"]]} } if exclude.any?
      }
    end

    def update(config)
      filepath = Pathname.new(TRAVIS_FILE)
      newtravis = build(config)
      oldtravis = YAML.load(filepath.read) rescue nil
      if oldtravis != newtravis
        header = <<-ENDYAML
# This file was auto-generated by the schema_dev tool, based on the data in
#                 ./schema_dev.yml
# Please do not edit this file; any changes will be overwritten next time
# schema_dev gets run.
ENDYAML
        filepath.write header + newtravis.to_yaml
        return true
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
schema_dev-1.3.0 lib/schema_dev/travis.rb
schema_dev-1.2.5 lib/schema_dev/travis.rb
schema_dev-1.2.4 lib/schema_dev/travis.rb
schema_dev-1.2.3 lib/schema_dev/travis.rb
schema_dev-1.2.2 lib/schema_dev/travis.rb