config_mapper 1.5.0 → 1.6.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: 071bbe40a32e09004ef7e5a12ddc9eb909b7e06a
4
- data.tar.gz: c49eff8eda1e383a3e02f72aa6c7baca0f8810c6
3
+ metadata.gz: cad2a71b7850554a0a981b18d91bb1198cd16f8a
4
+ data.tar.gz: 305d415a5243d35b97d4a9b881fe51fad55217c5
5
5
  SHA512:
6
- metadata.gz: 8f8f2fdbf001b744b04c2ceb39c64c5df448568ea4b4e915d12060f0571c6bc2a8ad0581b27a545403066881f79a98f3f1633de2239959d90558967e2392089e
7
- data.tar.gz: 51f1cffdbbccc557e8a13b7c0882b5cdaefef07d167971a79c22ffe20fc5153c37ae77c8381045c04681715514dabb8ef24e0c9b2334fef454b55a5fc3a67c89
6
+ metadata.gz: 91509bfa9e31c03bb8093c434942980cbd8616fffb22b7d0b4bf21f64edd01b750b7e9dd270c2d491452ae191455dcdf9c49724feb1d9f5076c3421c54d16c6d
7
+ data.tar.gz: 423dcae0bc0c14b13979fbf1a10980b43c5e669a23fa521ad8b864fba965f83f3e5ee5bab1c569a8b6c2c47de017570964bd08ae7ef3b0cd36f37cb20c3da6b1
data/README.md CHANGED
@@ -246,6 +246,12 @@ state.configure_with(data)
246
246
  #=> }
247
247
  ```
248
248
 
249
+ `ConfigStruct.from_data` instantiates an object from data, raising an exception if errors are encountered:
250
+
251
+ ```ruby
252
+ state = State.from_data(data)
253
+ ```
254
+
249
255
  ## License
250
256
 
251
257
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,6 +1,7 @@
1
1
  require "config_mapper"
2
2
  require "config_mapper/config_dict"
3
3
  require "config_mapper/factory"
4
+ require "config_mapper/mapping_error"
4
5
  require "config_mapper/validator"
5
6
 
6
7
  module ConfigMapper
@@ -11,6 +12,18 @@ module ConfigMapper
11
12
 
12
13
  class << self
13
14
 
15
+ # Instantiate from data.
16
+ #
17
+ # @param attribute_values [Hash] attribute values
18
+ # @raise [ConfigMapper::MappingError] on error
19
+ #
20
+ def from_data(attribute_values)
21
+ new.tap do |instance|
22
+ errors = instance.configure_with(attribute_values)
23
+ raise MappingError, errors if errors.any?
24
+ end
25
+ end
26
+
14
27
  # Defines reader and writer methods for the specified attribute.
15
28
  #
16
29
  # A `:default` value may be specified; otherwise, the attribute is
@@ -0,0 +1,26 @@
1
+ module ConfigMapper
2
+
3
+ # Thrown to indicate a problem parsing config.
4
+ #
5
+ class MappingError < StandardError
6
+
7
+ def initialize(errors_by_field)
8
+ @errors_by_field = errors_by_field
9
+ super(generate_message)
10
+ end
11
+
12
+ attr_reader :errors_by_field
13
+
14
+ private
15
+
16
+ def generate_message
17
+ result = "configuration error"
18
+ errors_by_field.each do |field, error|
19
+ result << "\n #{field[1..-1]} - #{error}"
20
+ end
21
+ result
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -1,5 +1,5 @@
1
1
  module ConfigMapper
2
2
 
3
- VERSION = "1.5.0".freeze
3
+ VERSION = "1.6.0".freeze
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.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-01 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,6 +67,7 @@ files:
67
67
  - lib/config_mapper/config_struct.rb
68
68
  - lib/config_mapper/factory.rb
69
69
  - lib/config_mapper/mapper.rb
70
+ - lib/config_mapper/mapping_error.rb
70
71
  - lib/config_mapper/object_mapper.rb
71
72
  - lib/config_mapper/validator.rb
72
73
  - lib/config_mapper/version.rb
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  version: '0'
91
92
  requirements: []
92
93
  rubyforge_project:
93
- rubygems_version: 2.6.12
94
+ rubygems_version: 2.6.13
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Maps config data onto plain old objects