travis-config 1.0.0.rc1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f96540c8353be57638c3e7bc3b649a581d2df086
4
- data.tar.gz: b6140d403624472488a8fb6ce88b8fc43969ddef
3
+ metadata.gz: aee4a6bf44828bb44bf30a91dbc9ca7028813495
4
+ data.tar.gz: 4db6880197343768cad8e0692fad58741367d198
5
5
  SHA512:
6
- metadata.gz: 23b23106676b996e2510d500bc3b759714e0c8f3342bd2051c19d5b8dc8a1ca188e88db5fdaea386b73801afa8f6863d347756a3e72cac9c36f38ed9d3fd40cd
7
- data.tar.gz: a5ec1c92c9ed4c2d405c2feeaf01aafa9817a59f14f4046e0c611e9d8c2c9abab889fee74c560983b7459dbdc6b2febc95a51eb8501b9b7bd0c964745ee730be
6
+ metadata.gz: 7498ab1b0c1b05c615d01ee2f17efac2cadb44f0bde156cb707fde3a624c1aca7d7170fbc7a54b1024ae3740f0bb90e40e197729d1a6ca32962f835893b1bbc6
7
+ data.tar.gz: d992acfaa9b8ace9e80ad07ac363e6d65204dd13dd4678dcee00935b608ea56a1f7b9f6151304939c6dbaae07c64788163728732134fdbc48bbb01b40373c106
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'hashr', '~> 2.0.0.rc1'
5
+ gem 'hashr', '~> 2.0.0'
6
6
 
7
7
  group :test do
8
8
  gem 'rspec', '~> 3.0'
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- travis-config (1.0.0.rc1)
5
- hashr (~> 2.0.0.rc1)
4
+ travis-config (1.0.0)
5
+ hashr (~> 2.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.2.5)
11
- hashr (2.0.0.rc1)
11
+ hashr (2.0.0)
12
12
  metaclass (0.0.4)
13
13
  mocha (1.1.0)
14
14
  metaclass (~> 0.0.1)
@@ -31,7 +31,7 @@ PLATFORMS
31
31
  ruby
32
32
 
33
33
  DEPENDENCIES
34
- hashr (~> 2.0.0.rc1)
34
+ hashr (~> 2.0.0)
35
35
  mocha (~> 1.1)
36
36
  rspec (~> 3.0)
37
37
  travis-config!
@@ -29,7 +29,7 @@ module Travis
29
29
  end
30
30
 
31
31
  def loaders(*names)
32
- names = [:files, :env, :heroku, :docker] if names.empty?
32
+ names = [:files, :heroku, :env, :docker] if names.empty?
33
33
  names.map { |name| const_get(camelize(name)).new }
34
34
  end
35
35
  end
@@ -1,14 +1,20 @@
1
1
  require 'travis/config/helpers'
2
2
  require 'travis/config/heroku/database'
3
+ require 'travis/config/heroku/memcached'
3
4
 
4
5
  module Travis
5
6
  class Config
6
7
  class Heroku
7
8
  include Helpers
8
9
 
9
- # TODO add rabbitmq, redis, memcached addons etc
10
10
  def load
11
- compact(database: database, logs_database: logs_database)
11
+ compact(
12
+ database: database,
13
+ logs_database: logs_database,
14
+ amqp: amqp,
15
+ redis: redis,
16
+ memcached: memcached
17
+ )
12
18
  end
13
19
 
14
20
  private
@@ -20,6 +26,18 @@ module Travis
20
26
  def logs_database
21
27
  Database.new(prefix: 'logs').config
22
28
  end
29
+
30
+ def amqp
31
+ compact(Url.parse(ENV['RABBITMQ_URL']).to_h)
32
+ end
33
+
34
+ def redis
35
+ compact(url: ENV['REDIS_URL'])
36
+ end
37
+
38
+ def memcached
39
+ Memcached.new.config
40
+ end
23
41
  end
24
42
  end
25
43
  end
@@ -1,44 +1,45 @@
1
+ require 'travis/config/heroku/url'
2
+
1
3
  module Travis
2
4
  class Config
3
5
  class Heroku
4
- class Database
6
+ class Database < Struct.new(:options)
5
7
  include Helpers
6
8
 
7
- URL = %r((?:.+?)://(?<username>.+):(?<password>.+)@(?<host>[^:]+):?(?<port>.*)/(?<database>.+))
8
9
  DEFAULTS = { adapter: 'postgresql', encoding: 'unicode' }
9
10
 
10
- attr_reader :options
11
-
12
- def initialize(options = {})
13
- @options = options
11
+ def config
12
+ config = parse_url
13
+ config = DEFAULTS.merge(config) unless config.empty?
14
+ config[:pool] = pool.to_i if pool
15
+ config
14
16
  end
15
17
 
16
- def config
17
- parse_url.tap do |config|
18
- config[:pool] = pool.to_i if pool
18
+ private
19
+
20
+ def parse_url
21
+ compact(Url.parse(url).to_h)
19
22
  end
20
- end
21
23
 
22
- def parse_url
23
- matches = URL.match(url.to_s)
24
- matches ? compact(Hash[matches.names.zip(matches.captures)]).merge(DEFAULTS) : {}
25
- end
24
+ def pool
25
+ env('DB_POOL', 'DATABASE_POOL_SIZE').compact.first
26
+ end
26
27
 
27
- def pool
28
- env('DB_POOL', 'DATABASE_POOL_SIZE').compact.first
29
- end
28
+ def url
29
+ env('DATABASE_URL').compact.first
30
+ end
30
31
 
31
- def url
32
- env('DATABASE_URL').compact.first
33
- end
32
+ def env(*keys)
33
+ ENV.values_at(*keys.map { |key| prefix(key) })
34
+ end
34
35
 
35
- def env(*keys)
36
- ENV.values_at(*keys.map { |key| prefix(key) })
37
- end
36
+ def prefix(key)
37
+ [options[:prefix], key].compact.join('_').upcase
38
+ end
38
39
 
39
- def prefix(key)
40
- [options[:prefix], key].compact.join('_').upcase
41
- end
40
+ def options
41
+ super || {}
42
+ end
42
43
  end
43
44
  end
44
45
  end
@@ -0,0 +1,31 @@
1
+ module Travis
2
+ class Config
3
+ class Heroku
4
+ class Memcached
5
+ include Helpers
6
+
7
+ def config
8
+ compact(servers: servers, options: options)
9
+ end
10
+
11
+ private
12
+
13
+ def servers
14
+ ENV['MEMCACHED_SERVERS']
15
+ end
16
+
17
+ def options
18
+ { username: username, password: password }
19
+ end
20
+
21
+ def username
22
+ ENV['MEMCACHED_USERNAME']
23
+ end
24
+
25
+ def password
26
+ ENV['MEMCACHED_PASSWORD']
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ require 'uri'
2
+
3
+ module Travis
4
+ class Config
5
+ class Heroku
6
+ module Url
7
+ Base = Struct.new(:username, :password, :host, :port, :database)
8
+ Postgres = Class.new(Base)
9
+ Redis = Class.new(Base)
10
+
11
+ class Amqp < Base
12
+ alias :vhost :database
13
+
14
+ def to_h
15
+ super.reject { |key, value| key == :database }.merge(vhost: vhost)
16
+ end
17
+ end
18
+
19
+ class << self
20
+ def parse(url)
21
+ return {} if url.nil? || url.empty?
22
+ uri = URI.parse(url)
23
+ const = const_get(camelize(uri.scheme))
24
+ const.new(uri.user, uri.password, uri.host, uri.port, uri.path[1..-1])
25
+ end
26
+
27
+ def camelize(string)
28
+ string.to_s.split('_').collect(&:capitalize).join
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module TravisConfig
2
- VERSION = '1.0.0.rc1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,18 @@
1
+ describe Travis::Config::Heroku, :Amqp do
2
+ let(:config) { Travis::Test::Config.load(:heroku) }
3
+ let(:url) { 'amqp://username:password@hostname:1234/vhost' }
4
+
5
+ before { ENV['RABBITMQ_URL'] = url }
6
+ after { ENV.delete('RABBITMQ_URL') }
7
+
8
+ it 'loads a RABBITMQ_URL' do
9
+ expect(config.amqp).to eq(
10
+ host: 'hostname',
11
+ port: 1234,
12
+ vhost: 'vhost',
13
+ username: 'username',
14
+ password: 'password',
15
+ prefetch: 1
16
+ )
17
+ end
18
+ end
@@ -1,15 +1,15 @@
1
- describe Travis::Config::Heroku do
1
+ describe Travis::Config::Heroku, :Database do
2
2
  let(:config) { Travis::Test::Config.load(:heroku) }
3
3
  let(:vars) { %w(DATABASE_URL DB_POOL DATABASE_POOL_SIZE LOGS_DATABASE_URL LOGS_DB_POOL LOGS_DATABASE_POOL_SIZE) }
4
4
  after { vars.each { |key| ENV.delete(key) } }
5
5
 
6
6
  it 'loads a DATABASE_URL with a port' do
7
- ENV['DATABASE_URL'] = 'postgres://username:password@hostname:port/database'
7
+ ENV['DATABASE_URL'] = 'postgres://username:password@hostname:1234/database'
8
8
 
9
- expect(config.database.to_hash).to eq(
9
+ expect(config.database).to eq(
10
10
  adapter: 'postgresql',
11
11
  host: 'hostname',
12
- port: 'port',
12
+ port: 1234,
13
13
  database: 'database',
14
14
  username: 'username',
15
15
  password: 'password',
@@ -20,7 +20,7 @@ describe Travis::Config::Heroku do
20
20
  it 'loads a DATABASE_URL without a port' do
21
21
  ENV['DATABASE_URL'] = 'postgres://username:password@hostname/database'
22
22
 
23
- expect(config.database.to_hash).to eq(
23
+ expect(config.database).to eq(
24
24
  adapter: 'postgresql',
25
25
  host: 'hostname',
26
26
  database: 'database',
@@ -31,13 +31,13 @@ describe Travis::Config::Heroku do
31
31
  end
32
32
 
33
33
  it 'loads DB_POOL' do
34
- ENV['DATABASE_URL'] = 'postgres://username:password@hostname:port/database'
34
+ ENV['DATABASE_URL'] = 'postgres://username:password@hostname:1234/database'
35
35
  ENV['DB_POOL'] = '25'
36
36
 
37
- expect(config.database.to_hash).to eq(
37
+ expect(config.database).to eq(
38
38
  adapter: 'postgresql',
39
39
  host: 'hostname',
40
- port: 'port',
40
+ port: 1234,
41
41
  database: 'database',
42
42
  username: 'username',
43
43
  password: 'password',
@@ -47,13 +47,13 @@ describe Travis::Config::Heroku do
47
47
  end
48
48
 
49
49
  it 'loads DATABASE_POOL_SIZE' do
50
- ENV['DATABASE_URL'] = 'postgres://username:password@hostname:port/database'
50
+ ENV['DATABASE_URL'] = 'postgres://username:password@hostname:1234/database'
51
51
  ENV['DATABASE_POOL_SIZE'] = '25'
52
52
 
53
- expect(config.database.to_hash).to eq(
53
+ expect(config.database).to eq(
54
54
  adapter: 'postgresql',
55
55
  host: 'hostname',
56
- port: 'port',
56
+ port: 1234,
57
57
  database: 'database',
58
58
  username: 'username',
59
59
  password: 'password',
@@ -63,12 +63,12 @@ describe Travis::Config::Heroku do
63
63
  end
64
64
 
65
65
  it 'loads a LOGS_DATABASE_URL with a port' do
66
- ENV['LOGS_DATABASE_URL'] = 'postgres://username:password@hostname:port/logs_database'
66
+ ENV['LOGS_DATABASE_URL'] = 'postgres://username:password@hostname:1234/logs_database'
67
67
 
68
- expect(config.logs_database.to_hash).to eq(
68
+ expect(config.logs_database).to eq(
69
69
  adapter: 'postgresql',
70
70
  host: 'hostname',
71
- port: 'port',
71
+ port: 1234,
72
72
  database: 'logs_database',
73
73
  username: 'username',
74
74
  password: 'password',
@@ -79,7 +79,7 @@ describe Travis::Config::Heroku do
79
79
  it 'loads a LOGS_DATABASE_URL without a port' do
80
80
  ENV['LOGS_DATABASE_URL'] = 'postgres://username:password@hostname/logs_database'
81
81
 
82
- expect(config.logs_database.to_hash).to eq(
82
+ expect(config.logs_database).to eq(
83
83
  adapter: 'postgresql',
84
84
  host: 'hostname',
85
85
  database: 'logs_database',
@@ -90,13 +90,13 @@ describe Travis::Config::Heroku do
90
90
  end
91
91
 
92
92
  it 'loads LOGS_DB_POOL' do
93
- ENV['LOGS_DATABASE_URL'] = 'postgres://username:password@hostname:port/logs_database'
93
+ ENV['LOGS_DATABASE_URL'] = 'postgres://username:password@hostname:1234/logs_database'
94
94
  ENV['LOGS_DB_POOL'] = '25'
95
95
 
96
- expect(config.logs_database.to_hash).to eq(
96
+ expect(config.logs_database).to eq(
97
97
  adapter: 'postgresql',
98
98
  host: 'hostname',
99
- port: 'port',
99
+ port: 1234,
100
100
  database: 'logs_database',
101
101
  username: 'username',
102
102
  password: 'password',
@@ -106,13 +106,13 @@ describe Travis::Config::Heroku do
106
106
  end
107
107
 
108
108
  it 'loads LOGS_DATABASE_POOL_SIZE' do
109
- ENV['LOGS_DATABASE_URL'] = 'postgres://username:password@hostname:port/logs_database'
109
+ ENV['LOGS_DATABASE_URL'] = 'postgres://username:password@hostname:1234/logs_database'
110
110
  ENV['LOGS_DATABASE_POOL_SIZE'] = '25'
111
111
 
112
- expect(config.logs_database.to_hash).to eq(
112
+ expect(config.logs_database).to eq(
113
113
  adapter: 'postgresql',
114
114
  host: 'hostname',
115
- port: 'port',
115
+ port: 1234,
116
116
  database: 'logs_database',
117
117
  username: 'username',
118
118
  password: 'password',
@@ -0,0 +1,23 @@
1
+ describe Travis::Config::Heroku, :Memcached do
2
+ let(:config) { Travis::Test::Config.load(:heroku) }
3
+ let(:servers) { 'hostname:1234' }
4
+ let(:username) { 'username' }
5
+ let(:password) { 'password' }
6
+
7
+ [:servers, :username, :password].each do |key|
8
+ before { ENV["MEMCACHED_#{key.to_s.upcase}"] = send(key) }
9
+ after { ENV.delete("MEMCACHED_#{key.to_s.upcase}") }
10
+ end
11
+
12
+ it 'loads a MEMCACHED_SERVERS' do
13
+ expect(config.memcached.servers).to eq(servers)
14
+ end
15
+
16
+ it 'loads a MEMCACHED_USERNAME' do
17
+ expect(config.memcached.options.username).to eq(username)
18
+ end
19
+
20
+ it 'loads a MEMCACHED_SERVERS' do
21
+ expect(config.memcached.options.password).to eq(password)
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ describe Travis::Config::Heroku, :Redis do
2
+ let(:config) { Travis::Test::Config.load(:heroku) }
3
+ let(:url) { 'redis://username:password@hostname:1234/database' }
4
+
5
+ before { ENV['REDIS_URL'] = url }
6
+ after { ENV.delete('REDIS_URL') }
7
+
8
+ it 'loads a REDIS_URL' do
9
+ expect(config.redis).to eq(url: url)
10
+ end
11
+ end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = TravisConfig::VERSION
9
9
  s.authors = ["Travis CI"]
10
10
  s.email = "contact@travis-ci.org"
11
- s.homepage = "https://github.com/travis-ci/travis-core"
11
+ s.homepage = "https://github.com/travis-ci/travis-config"
12
12
  s.summary = "Travis CI config"
13
13
  s.description = "#{s.summary}."
14
14
  s.license = "MIT"
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.require_path = 'lib'
19
19
  s.rubyforge_project = '[none]'
20
20
 
21
- s.add_dependency 'hashr', '~> 2.0.0.rc1'
21
+ s.add_dependency 'hashr', '~> 2.0.0'
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis CI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashr
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0.rc1
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0.rc1
26
+ version: 2.0.0
27
27
  description: Travis CI config.
28
28
  email: contact@travis-ci.org
29
29
  executables: []
@@ -41,14 +41,19 @@ files:
41
41
  - lib/travis/config/helpers.rb
42
42
  - lib/travis/config/heroku.rb
43
43
  - lib/travis/config/heroku/database.rb
44
+ - lib/travis/config/heroku/memcached.rb
45
+ - lib/travis/config/heroku/url.rb
44
46
  - lib/travis/config/version.rb
45
47
  - spec/spec_helper.rb
46
48
  - spec/travis/config/docker_spec.rb
47
49
  - spec/travis/config/files_spec.rb
48
- - spec/travis/config/heroku_spec.rb
50
+ - spec/travis/config/heroku/amqp_spec.rb
51
+ - spec/travis/config/heroku/database_spec.rb
52
+ - spec/travis/config/heroku/memcached_spec.rb
53
+ - spec/travis/config/heroku/redis_spec.rb
49
54
  - spec/travis/config_spec.rb
50
55
  - travis-config.gemspec
51
- homepage: https://github.com/travis-ci/travis-core
56
+ homepage: https://github.com/travis-ci/travis-config
52
57
  licenses:
53
58
  - MIT
54
59
  metadata: {}
@@ -63,9 +68,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
68
  version: '0'
64
69
  required_rubygems_version: !ruby/object:Gem::Requirement
65
70
  requirements:
66
- - - ">"
71
+ - - ">="
67
72
  - !ruby/object:Gem::Version
68
- version: 1.3.1
73
+ version: '0'
69
74
  requirements: []
70
75
  rubyforge_project: "[none]"
71
76
  rubygems_version: 2.4.5