Module: SchemaDev::Travis

Extended by:
Travis
Included in:
Travis
Defined in:
lib/schema_dev/travis.rb

Constant Summary collapse

TRAVIS_FILE =
".travis.yml"

Instance Method Summary collapse

Instance Method Details

#build(config) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/schema_dev/travis.rb', line 12

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

#update(config) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/schema_dev/travis.rb', line 39

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