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 +4 -4
- data/lib/txgh/config/provider_instance.rb +7 -2
- data/lib/txgh/config/provider_support.rb +4 -3
- data/lib/txgh/config/providers/file_provider.rb +4 -0
- data/lib/txgh/config/providers/git_provider.rb +4 -0
- data/lib/txgh/config/providers/raw_provider.rb +4 -0
- data/lib/txgh/version.rb +1 -1
- data/lib/txgh.rb +1 -1
- data/spec/config/provider_instance_spec.rb +14 -0
- data/spec/config/provider_support_spec.rb +18 -0
- data/spec/txgh_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fee2bdf0b9b179b4aab0a6c50983c51744e37ff
|
4
|
+
data.tar.gz: c2f2c4c1b5da524dd923cc76ddf81bf49c987720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
data/lib/txgh/version.rb
CHANGED
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
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.
|
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-
|
12
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: abroad
|