txgh 2.2.0 → 2.3.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: fa8e34cc2f842b5e1d9d6998b6ddbf0ce72dfab8
4
- data.tar.gz: 8d5dc86a7c315128114d6ff1e25b977ab908ee2a
3
+ metadata.gz: 5fee2bdf0b9b179b4aab0a6c50983c51744e37ff
4
+ data.tar.gz: c2f2c4c1b5da524dd923cc76ddf81bf49c987720
5
5
  SHA512:
6
- metadata.gz: 759259034ab336dcaeae29ecc692bfa45590a9f7bd11392162bb594a067acaf5bd152f6d248c5b27bd2af153950227a722f4364ac3b93db9aeb3e1258cc21a5b
7
- data.tar.gz: 198311603b7035fa0129cfb20e288eb5444842fd319a65d88c6bbcfb2b390829ae0819f935b91d177f145846992f1a0031a94cd78b768d48a18229af7f7e5318
6
+ metadata.gz: 3c9fda5138230919f88654b54bc594b7ad4edc0473b1863d44c618584c38558e5fc66f00b74902b8fe9a69ba49f7caed01e5be182e23bc1d80706432c2ae621d
7
+ data.tar.gz: 0a45f36602011a551fb06244073b8a101a1c89c6a6ef8078ce9c65af6da0c587c1d431a9fe9f88190cbac9d967706451eaaea0e5fa6d5c389611ccc67ca1aa1b
@@ -1,11 +1,12 @@
1
1
  module Txgh
2
2
  module Config
3
3
  class ProviderInstance
4
- attr_reader :provider, :parser
4
+ attr_reader :provider, :parser, :options
5
5
 
6
- def initialize(provider, parser)
6
+ def initialize(provider, parser, options = {})
7
7
  @provider = provider
8
8
  @parser = parser
9
+ @options = options
9
10
  end
10
11
 
11
12
  def supports?(*args)
@@ -15,6 +16,10 @@ module Txgh
15
16
  def load(payload, options = {})
16
17
  provider.load(payload, parser, options)
17
18
  end
19
+
20
+ def default?
21
+ !!(options[:default])
22
+ end
18
23
  end
19
24
  end
20
25
  end
@@ -1,8 +1,8 @@
1
1
  module Txgh
2
2
  module Config
3
3
  module ProviderSupport
4
- def register_provider(provider, parser)
5
- providers << ProviderInstance.new(provider, parser)
4
+ def register_provider(provider, parser, options = {})
5
+ providers << ProviderInstance.new(provider, parser, options)
6
6
  end
7
7
 
8
8
  def providers
@@ -10,7 +10,8 @@ module Txgh
10
10
  end
11
11
 
12
12
  def provider_for(scheme)
13
- providers.find { |provider| provider.supports?(scheme) }
13
+ provider = providers.find { |provider| provider.supports?(scheme) }
14
+ provider || providers.find(&:default?)
14
15
  end
15
16
 
16
17
  def split_uri(uri)
@@ -12,6 +12,10 @@ module Txgh
12
12
  def load(payload, parser, options = {})
13
13
  parser.load_file(payload)
14
14
  end
15
+
16
+ def scheme
17
+ SCHEME
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -12,6 +12,10 @@ module Txgh
12
12
  def load(payload, parser, options = {})
13
13
  new(payload, parser, options).config
14
14
  end
15
+
16
+ def scheme
17
+ SCHEME
18
+ end
15
19
  end
16
20
 
17
21
  attr_reader :payload, :parser
@@ -12,6 +12,10 @@ module Txgh
12
12
  def load(payload, parser, options = {})
13
13
  parser.load(payload)
14
14
  end
15
+
16
+ def scheme
17
+ SCHEME
18
+ end
15
19
  end
16
20
  end
17
21
  end
data/lib/txgh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Txgh
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
data/lib/txgh.rb CHANGED
@@ -65,7 +65,7 @@ module Txgh
65
65
  # default set of tx config providers
66
66
  tx_manager.register_provider(providers::FileProvider, Txgh::Config::TxConfig)
67
67
  tx_manager.register_provider(providers::GitProvider, Txgh::Config::TxConfig)
68
- tx_manager.register_provider(providers::RawProvider, Txgh::Config::TxConfig)
68
+ tx_manager.register_provider(providers::RawProvider, Txgh::Config::TxConfig, default: true)
69
69
 
70
70
  # default set of base config providers
71
71
  key_manager.register_provider(providers::FileProvider, YAML)
@@ -21,6 +21,20 @@ describe ProviderInstance do
21
21
  end
22
22
  end
23
23
 
24
+ describe '#default' do
25
+ it 'returns false if not the default provider' do
26
+ expect(instance).to_not be_default
27
+ end
28
+
29
+ context 'with a default provider' do
30
+ let(:instance) { ProviderInstance.new(provider, parser, default: true) }
31
+
32
+ it 'returns true if marked as the default provider' do
33
+ expect(instance).to be_default
34
+ end
35
+ end
36
+ end
37
+
24
38
  describe '#load' do
25
39
  it "calls the provider's load method passing the parser and options" do
26
40
  expect(provider).to receive(:load).with(payload, parser, options)
@@ -50,6 +50,24 @@ describe ProviderSupport do
50
50
  expect(instance.provider).to eq(provider)
51
51
  expect(instance.parser).to eq(:fake_parser)
52
52
  end
53
+
54
+ it 'returns nil when passed an unrecognizable scheme' do
55
+ expect(klass.provider_for('foo')).to be_nil
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'with a default registered provider' do
61
+ before(:each) do
62
+ klass.register_provider(provider, :fake_parser, default: true)
63
+ end
64
+
65
+ describe '#provider_for' do
66
+ it 'returns the default provider when passed an unrecognizable scheme' do
67
+ instance = klass.provider_for('foo')
68
+ expect(instance.provider).to eq(provider)
69
+ expect(instance.parser).to eq(:fake_parser)
70
+ end
53
71
  end
54
72
  end
55
73
  end
data/spec/txgh_spec.rb CHANGED
@@ -22,4 +22,11 @@ describe Txgh do
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ describe 'providers' do
27
+ it 'defaults to the raw tx config provider' do
28
+ instance = Txgh.tx_manager.provider_for('foo')
29
+ expect(instance.provider.scheme).to eq('raw')
30
+ end
31
+ end
25
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txgh
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Jackowski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-06 00:00:00.000000000 Z
12
+ date: 2016-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abroad