travis-config 0.1.4 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ceacc0f6edcb2ac39967e9aa9832ec98b9a9cba0
4
- data.tar.gz: f33a79c5c2c5d5a18e577ff91d5ea0a985dcfed4
3
+ metadata.gz: f96540c8353be57638c3e7bc3b649a581d2df086
4
+ data.tar.gz: b6140d403624472488a8fb6ce88b8fc43969ddef
5
5
  SHA512:
6
- metadata.gz: 9e0964efaa98ae82564b5e861d322b048f923125c1b4bc15ba5e1fe0369dd1032eef43d2ec3966b51078c737fa8367aff219d2530933b93dab7bde39ac38e0a4
7
- data.tar.gz: 013f0dc42b9cf4143a847db644aa6d92e878a0b2337884f2f61355da7320ca875f87c9959e3bf9fc98b184e7ea1ae53ec1d7ea967e4e2e0ccdd74674bc1de7f1
6
+ metadata.gz: 23b23106676b996e2510d500bc3b759714e0c8f3342bd2051c19d5b8dc8a1ca188e88db5fdaea386b73801afa8f6863d347756a3e72cac9c36f38ed9d3fd40cd
7
+ data.tar.gz: a5ec1c92c9ed4c2d405c2feeaf01aafa9817a59f14f4046e0c611e9d8c2c9abab889fee74c560983b7459dbdc6b2febc95a51eb8501b9b7bd0c964745ee730be
data/Gemfile CHANGED
@@ -2,6 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'hashr', '~> 2.0.0.rc1'
6
+
5
7
  group :test do
6
8
  gem 'rspec', '~> 3.0'
7
9
  gem 'mocha', '~> 1.1'
data/Gemfile.lock CHANGED
@@ -1,34 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- travis-config (0.1.3)
5
- hashr (~> 0.0)
4
+ travis-config (1.0.0.rc1)
5
+ hashr (~> 2.0.0.rc1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.2.5)
11
- hashr (0.0.22)
11
+ hashr (2.0.0.rc1)
12
12
  metaclass (0.0.4)
13
13
  mocha (1.1.0)
14
14
  metaclass (~> 0.0.1)
15
- rspec (3.1.0)
16
- rspec-core (~> 3.1.0)
17
- rspec-expectations (~> 3.1.0)
18
- rspec-mocks (~> 3.1.0)
19
- rspec-core (3.1.7)
20
- rspec-support (~> 3.1.0)
21
- rspec-expectations (3.1.2)
15
+ rspec (3.3.0)
16
+ rspec-core (~> 3.3.0)
17
+ rspec-expectations (~> 3.3.0)
18
+ rspec-mocks (~> 3.3.0)
19
+ rspec-core (3.3.2)
20
+ rspec-support (~> 3.3.0)
21
+ rspec-expectations (3.3.1)
22
22
  diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.1.0)
24
- rspec-mocks (3.1.3)
25
- rspec-support (~> 3.1.0)
26
- rspec-support (3.1.2)
23
+ rspec-support (~> 3.3.0)
24
+ rspec-mocks (3.3.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.3.0)
27
+ rspec-support (3.3.0)
27
28
 
28
29
  PLATFORMS
30
+ java
29
31
  ruby
30
32
 
31
33
  DEPENDENCIES
34
+ hashr (~> 2.0.0.rc1)
32
35
  mocha (~> 1.1)
33
36
  rspec (~> 3.0)
34
37
  travis-config!
38
+
39
+ BUNDLED WITH
40
+ 1.10.6
data/lib/travis/config.rb CHANGED
@@ -1,26 +1,14 @@
1
1
  require 'hashr'
2
- require 'travis/config/docker'
3
- require 'travis/config/env'
4
- require 'travis/config/files'
5
- require 'travis/config/heroku'
6
-
7
- # patch Hashr to merge with existing definitions and defaults
8
- class Hashr < Hash
9
- class << self
10
- def define(definition)
11
- definition = self.definition.merge(definition.deep_symbolize_keys)
12
- @definition = deep_accessorize(definition)
13
- end
14
-
15
- def default(defaults)
16
- defaults = self.defaults.merge(defaults)
17
- @defaults = deep_accessorize(defaults)
18
- end
19
- end
20
- end
21
2
 
22
3
  module Travis
23
4
  class Config < Hashr
5
+ require 'travis/config/docker'
6
+ require 'travis/config/env'
7
+ require 'travis/config/files'
8
+ require 'travis/config/heroku'
9
+
10
+ include Hashr::Delegate::Conditional
11
+
24
12
  class << self
25
13
  include Helpers
26
14
 
@@ -28,17 +16,22 @@ module Travis
28
16
  @env ||= ENV['ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
29
17
  end
30
18
 
31
- def load(*loaders)
32
- loaders = [:files, :env, :heroku, :docker] if loaders.empty?
19
+ def load(*names)
20
+ new(load_from(*names))
21
+ end
22
+
23
+ private
33
24
 
34
- data = loaders.inject({}) do |data, name|
35
- const = const_get(camelize(name)).new
36
- other = deep_symbolize_keys(const.load)
37
- deep_merge(data, other)
25
+ def load_from(*names)
26
+ loaders(*names).inject({}) do |data, loader|
27
+ deep_merge(data, deep_symbolize_keys(loader.load))
28
+ end
38
29
  end
39
30
 
40
- new(data)
41
- end
31
+ def loaders(*names)
32
+ names = [:files, :env, :heroku, :docker] if names.empty?
33
+ names.map { |name| const_get(camelize(name)).new }
34
+ end
42
35
  end
43
36
 
44
37
  def env
@@ -1,8 +1,7 @@
1
- require 'hashr'
2
1
  require 'travis/config/helpers'
3
2
 
4
3
  module Travis
5
- class Config < Hashr
4
+ class Config
6
5
  class Docker
7
6
  include Helpers
8
7
 
@@ -1,7 +1,5 @@
1
- require 'hashr'
2
-
3
1
  module Travis
4
- class Config < Hashr
2
+ class Config
5
3
  class Env
6
4
  def load
7
5
  ENV['travis_config'] ? YAML.load(ENV['travis_config']) : {}
@@ -1,9 +1,8 @@
1
1
  require 'yaml'
2
- require 'hashr'
3
2
  require 'travis/config/helpers'
4
3
 
5
4
  module Travis
6
- class Config < Hashr
5
+ class Config
7
6
  class Files
8
7
  include Helpers
9
8
 
@@ -1,7 +1,5 @@
1
- require 'hashr'
2
-
3
1
  module Travis
4
- class Config < Hashr
2
+ class Config
5
3
  module Helpers
6
4
  def deep_symbolize_keys(hash)
7
5
  hash.inject({}) do |result, (key, value)|
@@ -40,11 +38,10 @@ module Travis
40
38
  end
41
39
 
42
40
  def camelize(string)
43
- string = string.to_s
44
- string = string.sub(/^[a-z\d]*/) { $&.capitalize }
45
- string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
46
- string.gsub!('/', '::')
47
- string
41
+ string.to_s.
42
+ sub(/^[a-z\d]*/) { $&.capitalize }.
43
+ gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }.
44
+ gsub('/', '::')
48
45
  end
49
46
  end
50
47
  end
@@ -1,13 +1,12 @@
1
- require 'hashr'
2
1
  require 'travis/config/helpers'
2
+ require 'travis/config/heroku/database'
3
3
 
4
4
  module Travis
5
- class Config < Hashr
5
+ class Config
6
6
  class Heroku
7
7
  include Helpers
8
8
 
9
- DATABASE_URL = %r((?:.+?)://(?<username>.+):(?<password>.+)@(?<host>[^:]+):?(?<port>.*)/(?<database>.+))
10
-
9
+ # TODO add rabbitmq, redis, memcached addons etc
11
10
  def load
12
11
  compact(database: database, logs_database: logs_database)
13
12
  end
@@ -15,36 +14,11 @@ module Travis
15
14
  private
16
15
 
17
16
  def database
18
- config = parse_database_url(database_url)
19
- config = config.merge(pool: pool_size.to_i) if pool_size
20
- config
17
+ Database.new.config
21
18
  end
22
19
 
23
20
  def logs_database
24
- config = parse_database_url(logs_database_url)
25
- config = config.merge(pool: logs_pool_size.to_i) if logs_pool_size
26
- config.merge(adapter: 'postgresql', encoding: 'unicode') unless config.empty?
27
- end
28
-
29
- def parse_database_url(url)
30
- matches = DATABASE_URL.match(url.to_s)
31
- matches ? compact(Hash[matches.names.zip(matches.captures)]) : {}
32
- end
33
-
34
- def pool_size
35
- ENV.values_at('DB_POOL', 'DATABASE_POOL_SIZE').compact.first
36
- end
37
-
38
- def logs_pool_size
39
- ENV.values_at('LOGS_DB_POOL', 'LOGS_DATABASE_POOL_SIZE').compact.first
40
- end
41
-
42
- def database_url
43
- ENV.values_at('DATABASE_URL', 'SHARED_DATABASE_URL').compact.first
44
- end
45
-
46
- def logs_database_url
47
- ENV.values_at('LOGS_DATABASE_URL', 'SHARED_LOGS_DATABASE_URL').compact.first
21
+ Database.new(prefix: 'logs').config
48
22
  end
49
23
  end
50
24
  end
@@ -0,0 +1,45 @@
1
+ module Travis
2
+ class Config
3
+ class Heroku
4
+ class Database
5
+ include Helpers
6
+
7
+ URL = %r((?:.+?)://(?<username>.+):(?<password>.+)@(?<host>[^:]+):?(?<port>.*)/(?<database>.+))
8
+ DEFAULTS = { adapter: 'postgresql', encoding: 'unicode' }
9
+
10
+ attr_reader :options
11
+
12
+ def initialize(options = {})
13
+ @options = options
14
+ end
15
+
16
+ def config
17
+ parse_url.tap do |config|
18
+ config[:pool] = pool.to_i if pool
19
+ end
20
+ end
21
+
22
+ def parse_url
23
+ matches = URL.match(url.to_s)
24
+ matches ? compact(Hash[matches.names.zip(matches.captures)]).merge(DEFAULTS) : {}
25
+ end
26
+
27
+ def pool
28
+ env('DB_POOL', 'DATABASE_POOL_SIZE').compact.first
29
+ end
30
+
31
+ def url
32
+ env('DATABASE_URL').compact.first
33
+ end
34
+
35
+ def env(*keys)
36
+ ENV.values_at(*keys.map { |key| prefix(key) })
37
+ end
38
+
39
+ def prefix(key)
40
+ [options[:prefix], key].compact.join('_').upcase
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module TravisConfig
2
- VERSION = '0.1.4'
2
+ VERSION = '1.0.0.rc1'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -13,3 +13,4 @@ end
13
13
  RSpec.configure do |config|
14
14
  config.mock_with :mocha
15
15
  end
16
+
@@ -20,14 +20,8 @@ describe Travis::Config do
20
20
  expect(config.foo.bar).to be_kind_of(Hashr)
21
21
  end
22
22
 
23
- it 'can access all keys recursively' do
24
- access = proc do |config|
25
- config.keys.each do |key|
26
- expect(proc { config.send(key) }).to_not raise_error
27
- access.call(config.send(key)) if config[key].is_a?(Hash)
28
- end
29
- end
30
- access.call(config)
23
+ it 'can access nested keys' do
24
+ expect(config.amqp.username).to eq('guest')
31
25
  end
32
26
  end
33
27
 
@@ -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', '~> 0.0'
21
+ s.add_dependency 'hashr', '~> 2.0.0.rc1'
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: 0.1.4
4
+ version: 1.0.0.rc1
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-09-11 00:00:00.000000000 Z
11
+ date: 2015-10-07 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: '0.0'
19
+ version: 2.0.0.rc1
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: '0.0'
26
+ version: 2.0.0.rc1
27
27
  description: Travis CI config.
28
28
  email: contact@travis-ci.org
29
29
  executables: []
@@ -40,6 +40,7 @@ files:
40
40
  - lib/travis/config/files.rb
41
41
  - lib/travis/config/helpers.rb
42
42
  - lib/travis/config/heroku.rb
43
+ - lib/travis/config/heroku/database.rb
43
44
  - lib/travis/config/version.rb
44
45
  - spec/spec_helper.rb
45
46
  - spec/travis/config/docker_spec.rb
@@ -62,9 +63,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
63
  version: '0'
63
64
  required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  requirements:
65
- - - ">="
66
+ - - ">"
66
67
  - !ruby/object:Gem::Version
67
- version: '0'
68
+ version: 1.3.1
68
69
  requirements: []
69
70
  rubyforge_project: "[none]"
70
71
  rubygems_version: 2.4.5