config_mapper 1.3.1 → 1.4.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: 6a259676c65e3f31f8bb022dde4518228e3225b6
4
- data.tar.gz: 9206d330467a7ce78b20dfd8ea65141fcca05c68
3
+ metadata.gz: 7de0e012b37758b972449905dd89e25fff9c5f78
4
+ data.tar.gz: ea363b40759c5fa82e7531c088486eb535dc30f3
5
5
  SHA512:
6
- metadata.gz: 2018f4d172e55dc3662c1597a7085cfb5fff61c1d6f5b6a319b5be94c80efe7cec9b16fd48c740beb7c1ddcb88a268585d152d581d30e6fd2d141633a39d961e
7
- data.tar.gz: afeeb59ae60d9736f5d264d6b4c0b1562ac8b1f3ddb4ce3b64656857903d515caa65f29fc6f93f7cf4dce55cd24691db935e2142106dccabd32fb89a3a87598b
6
+ metadata.gz: c4fa80171dd00dfec8c0dfc7a6f561bfe400045e01713bf928136d21ab6fe3df3fe06c212620ab16c6d8b9b5e452e3217b5fa7be52fe90fbec8031724e0f1009
7
+ data.tar.gz: 2fcacd97d600bb870f84ef1c8c7c9b3c991ef383db9ee6965bffb63be81d6c15de6ca461e8b8acc90fb4fababcdd9d40a67bac2647bd4127c60bc4e97b8cc282
@@ -102,10 +102,17 @@ module ConfigMapper
102
102
  @declared_component_dicts ||= []
103
103
  end
104
104
 
105
+ def for_all(attribute, &action)
106
+ ancestors.each do |klass|
107
+ next unless klass.respond_to?(attribute)
108
+ klass.public_send(attribute).each(&action)
109
+ end
110
+ end
111
+
105
112
  end
106
113
 
107
114
  def initialize
108
- self.class.attribute_initializers.each do |name, initializer|
115
+ self.class.for_all(:attribute_initializers) do |name, initializer|
109
116
  instance_variable_set("@#{name}", initializer.call)
110
117
  end
111
118
  end
@@ -134,7 +141,7 @@ module ConfigMapper
134
141
  #
135
142
  def to_h
136
143
  {}.tap do |result|
137
- self.class.attribute_initializers.keys.each do |attr_name|
144
+ self.class.for_all(:attribute_initializers) do |attr_name, _|
138
145
  value = send(attr_name)
139
146
  if value && value.respond_to?(:to_h) && !value.is_a?(Array)
140
147
  value = value.to_h
@@ -148,10 +155,10 @@ module ConfigMapper
148
155
 
149
156
  def components
150
157
  {}.tap do |result|
151
- self.class.declared_components.each do |name|
158
+ self.class.for_all(:declared_components) do |name|
152
159
  result[".#{name}"] = instance_variable_get("@#{name}")
153
160
  end
154
- self.class.declared_component_dicts.each do |name|
161
+ self.class.for_all(:declared_component_dicts) do |name|
155
162
  instance_variable_get("@#{name}").each do |key, value|
156
163
  result[".#{name}[#{key.inspect}]"] = value
157
164
  end
@@ -169,7 +176,7 @@ module ConfigMapper
169
176
 
170
177
  def missing_required_attribute_errors
171
178
  {}.tap do |errors|
172
- self.class.required_attributes.each do |name|
179
+ self.class.for_all(:required_attributes) do |name|
173
180
  if instance_variable_get("@#{name}").nil?
174
181
  errors[".#{name}"] = NoValueProvided.new
175
182
  end
@@ -1,5 +1,5 @@
1
1
  module ConfigMapper
2
2
 
3
- VERSION = "1.3.1".freeze
3
+ VERSION = "1.4.1".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.3.1
4
+ version: 1.4.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-11-18 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.4.5.1
91
+ rubygems_version: 2.6.12
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Maps config data onto plain old objects