configuru 0.1.1 → 0.1.2

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: 9afa59fbf6810cce708f1d83b2c10f0c66023072
4
- data.tar.gz: 7db11437ea98c4b7d884bd5ac33f3323dc851f79
3
+ metadata.gz: 9f047ca6c85515cbafa07bda7e8f8133435b502a
4
+ data.tar.gz: cdcc845fb86f48eb4fea80adf0b9534aeae44b53
5
5
  SHA512:
6
- metadata.gz: 8c3153582db20d9bccebf17ee2648af211b66bc8ba6a23c5373aea1f09d0630f3f062c7fd1d0aea90059f008be44af8ef58bccedba11a2572543854279d2d095
7
- data.tar.gz: b54582a521c9a7ea4525ef4966b05ceb55a8a721955655e41f47dce8a894a5b7c692d67ef42765d1e14948828e279478eea6ebf3fd53162f37fa9f5fe549de0a
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)
@@ -1,3 +1,3 @@
1
1
  module Configuru
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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 << subject
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - moonfly (Andrey Pronin)