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 +4 -4
- data/lib/config_mapper.rb +8 -7
- data/lib/config_mapper/config_dict.rb +26 -0
- data/lib/config_mapper/config_struct.rb +1 -22
- data/lib/config_mapper/{hash_target.rb → dict_mapper.rb} +2 -2
- data/lib/config_mapper/{target.rb → mapper.rb} +2 -2
- data/lib/config_mapper/{object_target.rb → object_mapper.rb} +2 -2
- data/lib/config_mapper/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ef98e7511cb9930fbda99d63064fc49e7634c25
|
4
|
+
data.tar.gz: b22f51b95e5248c20f91f353fddbd304b0a6ed26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eafa293ee0625f4c8d330f00f59a2618affeff679d5189e24087734cd4601f45bf32c0f7fdfaf380e643c7a9a0762b34581a6efc2f918eae237fc918e35b02e8
|
7
|
+
data.tar.gz: f59d8a5d5a27502ae8bb457aa083a14be7d2f35be5af3a2550d2347142ab452bfb76b25f17f343e6fd193ea267cdcadb8049853366ebba2b21699aa37c1b1cef
|
data/lib/config_mapper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require "config_mapper/
|
2
|
-
require "config_mapper/
|
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
|
-
|
25
|
+
mapper_for(target).configure_with(data)
|
25
26
|
end
|
26
27
|
|
27
28
|
alias_method :set, :configure_with
|
28
29
|
|
29
|
-
def
|
30
|
-
if target.is_a?(Hash)
|
31
|
-
|
30
|
+
def mapper_for(target)
|
31
|
+
if target.is_a?(Hash) || target.is_a?(ConfigMapper::ConfigDict)
|
32
|
+
DictMapper.new(target)
|
32
33
|
else
|
33
|
-
|
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 "
|
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
|
@@ -2,13 +2,13 @@ module ConfigMapper
|
|
2
2
|
|
3
3
|
# Something that accepts configuration.
|
4
4
|
#
|
5
|
-
class
|
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
|
11
|
+
def configure_with(data)
|
12
12
|
errors = {}
|
13
13
|
data.each do |key, value|
|
14
14
|
configure_attribute(key, value, errors)
|
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.
|
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-
|
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/
|
75
|
-
- lib/config_mapper/
|
76
|
-
- lib/config_mapper/
|
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.
|
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
|