bibliotech 0.2.7 → 0.2.8

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: f8ab1fe00c875d062b981cd72231994461afabe4
4
- data.tar.gz: 79859147aae212198e852bf30f67781bbae12ef4
3
+ metadata.gz: b70db645dc570547b493dda820ee2de92ea533f5
4
+ data.tar.gz: 0173bfc09213a275f488c02157b15a31eefec375
5
5
  SHA512:
6
- metadata.gz: d3f106ed97cf3b468010ada6c7d8876724dd2f6f6f8a3b31f15d6c29491701b78c273c10eab65ad164a9def9ba2eac203ee99ea5c1c65dd105f397ed3fb788db
7
- data.tar.gz: eea6a2754eb6f02cd7c393388afe37c2c6d69a3cfed71881e1702f82dec1566d5081043318e5d37d2893d0ba5514336209e15b4cb7879b011750f002d4238bcd
6
+ metadata.gz: 9f20dfa5184e4e2e7c2858ce1f39eb74e3b4555f9b8d49b79be864a4fdbebb3a7e551874a1e00985584c9fdab8c9afee88a173bc7ee08d917c9830f8b8abb830
7
+ data.tar.gz: 1174441ee8b6f34103df557508bfe4b066a336553f8c3f9705fdd5ee1c57ec81a6e7f3ad9cf86a5e67fee667d1d35ac5719d9111715d0d4d05094cd2f0ce0282
@@ -4,7 +4,7 @@ module BiblioTech
4
4
  module Builders
5
5
  class Database < Base
6
6
  def self.find_class(config)
7
- adapter_registry.fetch(config.adapter) do
7
+ adapter_registry.fetch(config.adapter.to_s) do
8
8
  raise "config.adapter is #{config.adapter.inspect} - supported adapters are #{supported_adapters.join(", ")}"
9
9
  end
10
10
  end
@@ -4,16 +4,11 @@ module BiblioTech
4
4
  module Builders
5
5
  class File < Base
6
6
  def self.find_class(config)
7
- file = config.backup_file
8
-
9
7
  explicit = find_explicit(config)
10
8
  return explicit unless explicit.nil?
11
9
 
12
- _, klass = adapter_registry.find{ |pattern, klass|
13
- next if pattern.is_a? Symbol
14
- file =~ pattern
15
- }
16
- klass || identity_adapter
10
+ file = config.backup_file
11
+ adapter_registry.fetch(file){ identity_adapter }
17
12
  rescue Config::MissingConfig
18
13
  return NullAdapter
19
14
  end
@@ -2,9 +2,49 @@ module BiblioTech
2
2
  module Builders
3
3
  class Base
4
4
  include Caliph::CommandLineDSL
5
+
6
+ class AdapterRegistry
7
+ def initialize
8
+ @hash = {}
9
+ @has_regexp = false
10
+ end
11
+
12
+ def put(name, value)
13
+ if name.is_a?(Regexp)
14
+ @has_regexp = true
15
+ else
16
+ name = name.to_s
17
+ end
18
+ @hash[name] = value
19
+ end
20
+
21
+ def fetch(name)
22
+ @hash.fetch(name.to_s) do
23
+ klass = nil
24
+ if @has_regexp
25
+ _, klass = @hash.find{ |pattern, klass|
26
+ next unless pattern.is_a? Regexp
27
+ name =~ pattern
28
+ }
29
+ end
30
+
31
+ if klass.nil?
32
+ if block_given?
33
+ yield
34
+ else
35
+ raise KeyError, "No adapter registered for #{name} - try #{@hash.keys.join(", ")}"
36
+ end
37
+ else
38
+ klass
39
+ end
40
+ end
41
+ end
42
+ end
43
+
5
44
  class << self
45
+
6
46
  def register(adapter_name)
7
- adapter_registry[adapter_name] = self
47
+ adapter_registry.put(adapter_name, self)
8
48
  end
9
49
 
10
50
  def adapter_registry
@@ -12,7 +52,7 @@ module BiblioTech
12
52
  end
13
53
 
14
54
  def registry
15
- @registry ||={}
55
+ @registry ||= AdapterRegistry.new
16
56
  end
17
57
 
18
58
  def supported_adapters
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliotech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Dorn
@@ -128,7 +128,7 @@ rdoc_options:
128
128
  - --main
129
129
  - doc/README
130
130
  - --title
131
- - bibliotech-0.2.7 Documentation
131
+ - bibliotech-0.2.8 Documentation
132
132
  require_paths:
133
133
  - lib/
134
134
  required_ruby_version: !ruby/object:Gem::Requirement