configuru 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/configuru/config_methods.rb +7 -1
- data/lib/configuru/configurable.rb +5 -2
- data/lib/configuru/version.rb +1 -1
- data/spec/configuru/config_methods_spec.rb +28 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f047ca6c85515cbafa07bda7e8f8133435b502a
|
4
|
+
data.tar.gz: cdcc845fb86f48eb4fea80adf0b9534aeae44b53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebb60ce6b4da2406809fc90d60d746fa1b7645ac23b58e151a48e3570c2f2e759164f79dbaca1f206d01d0d4ae83aacb46d8585d84e51f6f30c3b609957be6d0
|
7
|
+
data.tar.gz: c428bbc607774c9b971fa0b88d0b21cfbfe6f697d7413a0f0230e3063d1f3c641eba9d5f5db3eda17f320622c6fcc8eef92125a9b4ef3e1ccffafbf69756bca7
|
@@ -61,7 +61,7 @@ module Configuru
|
|
61
61
|
end
|
62
62
|
if options.has_key?(:convert)
|
63
63
|
if options[:convert].is_a? Symbol
|
64
|
-
value = send options[:convert], value
|
64
|
+
value = @__parent_object.send options[:convert], value
|
65
65
|
else
|
66
66
|
value = options[:convert].call( value )
|
67
67
|
end
|
@@ -81,6 +81,12 @@ module Configuru
|
|
81
81
|
@locked = false unless instance_variable_defined?(:@locked)
|
82
82
|
@locked
|
83
83
|
end
|
84
|
+
def param_names
|
85
|
+
self.class.param_names
|
86
|
+
end
|
87
|
+
def set_parent_object(object)
|
88
|
+
@__parent_object = object
|
89
|
+
end
|
84
90
|
|
85
91
|
def configure(options={})
|
86
92
|
Hash(options).each_pair do |name,value|
|
@@ -6,7 +6,10 @@ module Configuru
|
|
6
6
|
def_delegator :configuration_class, :param, :def_config_param
|
7
7
|
def configuration_class
|
8
8
|
@configuration_class ||= Class.new do
|
9
|
-
include Configuru::ConfigMethods
|
9
|
+
include Configuru::ConfigMethods
|
10
|
+
def initialize(parent)
|
11
|
+
set_parent_object parent
|
12
|
+
end
|
10
13
|
end
|
11
14
|
end
|
12
15
|
def provide_configuration(limit_to=false)
|
@@ -24,7 +27,7 @@ module Configuru
|
|
24
27
|
|
25
28
|
module MainMethods
|
26
29
|
def configuration
|
27
|
-
@configuruation ||= configuration_class.new
|
30
|
+
@configuruation ||= configuration_class.new(self)
|
28
31
|
end
|
29
32
|
def configure(options,&block)
|
30
33
|
configuration.configure(options,&block)
|
data/lib/configuru/version.rb
CHANGED
@@ -269,11 +269,14 @@ describe Configuru::ConfigMethods do
|
|
269
269
|
end
|
270
270
|
|
271
271
|
it 'allows specifying a custom conversion method' do
|
272
|
-
class
|
272
|
+
class Parent
|
273
273
|
def check_for_x(value)
|
274
274
|
raise "X is not allowed" if value == "x"
|
275
275
|
"ok"
|
276
276
|
end
|
277
|
+
end
|
278
|
+
subject.set_parent_object(Parent.new)
|
279
|
+
class << subject
|
277
280
|
param :test1, convert: :check_for_x
|
278
281
|
param :test2, convert: ->(value) { value+1 }
|
279
282
|
end
|
@@ -284,4 +287,28 @@ describe Configuru::ConfigMethods do
|
|
284
287
|
expect{subject.test2=7}.not_to raise_error
|
285
288
|
expect(subject.test2).to eq 8
|
286
289
|
end
|
290
|
+
|
291
|
+
it 'accesses the conversion method from the specified parent object, not itself' do
|
292
|
+
class Parent
|
293
|
+
def check_for_x2(value)
|
294
|
+
raise "X is not allowed" if value == "x"
|
295
|
+
"ok"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
subject.set_parent_object(Parent.new)
|
299
|
+
class << subject
|
300
|
+
def check_for_x1(value)
|
301
|
+
raise "X is not allowed" if value == "x"
|
302
|
+
"ok"
|
303
|
+
end
|
304
|
+
param :test1, convert: :check_for_x1
|
305
|
+
param :test2, convert: :check_for_x2
|
306
|
+
end
|
307
|
+
expect{subject.test1=3}.to raise_error
|
308
|
+
expect{subject.test1="x"}.to raise_error
|
309
|
+
|
310
|
+
expect{subject.test2=3}.not_to raise_error
|
311
|
+
expect(subject.test2).to eq "ok"
|
312
|
+
expect{subject.test2="x"}.to raise_error
|
313
|
+
end
|
287
314
|
end
|