config_mapper 1.1.0 → 1.1.1

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: b3eceb23aa75978730fec0b82c9a01185852d056
4
- data.tar.gz: 155083970129df5b800a6085957a21c98e869f1e
3
+ metadata.gz: 8ef98e7511cb9930fbda99d63064fc49e7634c25
4
+ data.tar.gz: b22f51b95e5248c20f91f353fddbd304b0a6ed26
5
5
  SHA512:
6
- metadata.gz: 4c959618d4f898cc3e49c3512042c043b5b5a4b26cb7a9287e6620832fc53be5de77950fc7e7d551695c203ef8a8235a361e20db5f5d557bad0834f2e63075c1
7
- data.tar.gz: 128a784d48f8933c27c83d55e754889b43f9eb6e61451ca6a4e23162e88175a6b53ad8e1a8cb27f156bac796767e6715d08b07c82f632b50433825b172842837
6
+ metadata.gz: eafa293ee0625f4c8d330f00f59a2618affeff679d5189e24087734cd4601f45bf32c0f7fdfaf380e643c7a9a0762b34581a6efc2f918eae237fc918e35b02e8
7
+ data.tar.gz: f59d8a5d5a27502ae8bb457aa083a14be7d2f35be5af3a2550d2347142ab452bfb76b25f17f343e6fd193ea267cdcadb8049853366ebba2b21699aa37c1b1cef
data/lib/config_mapper.rb CHANGED
@@ -1,5 +1,6 @@
1
- require "config_mapper/hash_target"
2
- require "config_mapper/object_target"
1
+ require "config_mapper/config_dict"
2
+ require "config_mapper/dict_mapper"
3
+ require "config_mapper/object_mapper"
3
4
 
4
5
  # Supports marshalling of plain-old data (e.g. loaded from
5
6
  # YAML files) onto strongly-typed objects.
@@ -21,16 +22,16 @@ module ConfigMapper
21
22
  # @return [Hash] exceptions encountered
22
23
  #
23
24
  def configure_with(data, target)
24
- target(target).with(data)
25
+ mapper_for(target).configure_with(data)
25
26
  end
26
27
 
27
28
  alias_method :set, :configure_with
28
29
 
29
- def target(target)
30
- if target.is_a?(Hash)
31
- HashTarget.new(target)
30
+ def mapper_for(target)
31
+ if target.is_a?(Hash) || target.is_a?(ConfigMapper::ConfigDict)
32
+ DictMapper.new(target)
32
33
  else
33
- ObjectTarget.new(target)
34
+ ObjectMapper.new(target)
34
35
  end
35
36
  end
36
37
 
@@ -0,0 +1,26 @@
1
+ require "forwardable"
2
+
3
+ module ConfigMapper
4
+
5
+ class ConfigDict
6
+
7
+ def initialize(entry_type, key_type = nil)
8
+ @entry_type = entry_type
9
+ @key_type = key_type
10
+ @entries = {}
11
+ end
12
+
13
+ def [](key)
14
+ key = @key_type.call(key) if @key_type
15
+ @entries[key] ||= @entry_type.call
16
+ end
17
+
18
+ extend Forwardable
19
+
20
+ def_delegators :@entries, :each, :empty?, :keys, :map, :size
21
+
22
+ include Enumerable
23
+
24
+ end
25
+
26
+ end
@@ -1,5 +1,5 @@
1
1
  require "config_mapper"
2
- require "forwardable"
2
+ require "config_mapper/config_dict"
3
3
 
4
4
  module ConfigMapper
5
5
 
@@ -165,25 +165,4 @@ module ConfigMapper
165
165
 
166
166
  end
167
167
 
168
- class ConfigDict
169
-
170
- def initialize(entry_type, key_type = nil)
171
- @entry_type = entry_type
172
- @key_type = key_type
173
- @entries = {}
174
- end
175
-
176
- def [](key)
177
- key = @key_type.call(key) if @key_type
178
- @entries[key] ||= @entry_type.call
179
- end
180
-
181
- extend Forwardable
182
-
183
- def_delegators :@entries, :each, :empty?, :keys, :map, :size
184
-
185
- include Enumerable
186
-
187
- end
188
-
189
168
  end
@@ -1,10 +1,10 @@
1
- require "config_mapper/target"
1
+ require "config_mapper/mapper"
2
2
 
3
3
  module ConfigMapper
4
4
 
5
5
  # Configuration proxy for a Hash.
6
6
  #
7
- class HashTarget < Target
7
+ class DictMapper < Mapper
8
8
 
9
9
  def initialize(hash)
10
10
  @hash = hash
@@ -2,13 +2,13 @@ module ConfigMapper
2
2
 
3
3
  # Something that accepts configuration.
4
4
  #
5
- class Target
5
+ class Mapper
6
6
 
7
7
  # Map configuration data onto the target.
8
8
  #
9
9
  # @return [Hash] exceptions encountered
10
10
  #
11
- def with(data)
11
+ def configure_with(data)
12
12
  errors = {}
13
13
  data.each do |key, value|
14
14
  configure_attribute(key, value, errors)
@@ -1,10 +1,10 @@
1
- require "config_mapper/target"
1
+ require "config_mapper/mapper"
2
2
 
3
3
  module ConfigMapper
4
4
 
5
5
  # Configuration proxy for an Object.
6
6
  #
7
- class ObjectTarget < Target
7
+ class ObjectMapper < Mapper
8
8
 
9
9
  def initialize(object)
10
10
  @object = object
@@ -1,5 +1,5 @@
1
1
  module ConfigMapper
2
2
 
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-14 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,10 +70,11 @@ files:
70
70
  - Rakefile
71
71
  - config_mapper.gemspec
72
72
  - lib/config_mapper.rb
73
+ - lib/config_mapper/config_dict.rb
73
74
  - lib/config_mapper/config_struct.rb
74
- - lib/config_mapper/hash_target.rb
75
- - lib/config_mapper/object_target.rb
76
- - lib/config_mapper/target.rb
75
+ - lib/config_mapper/dict_mapper.rb
76
+ - lib/config_mapper/mapper.rb
77
+ - lib/config_mapper/object_mapper.rb
77
78
  - lib/config_mapper/version.rb
78
79
  homepage: https://github.com/mdub/config_mapper
79
80
  licenses:
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  version: '0'
96
97
  requirements: []
97
98
  rubyforge_project:
98
- rubygems_version: 2.5.0
99
+ rubygems_version: 2.5.2
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: Maps config data onto plain old objects