super_recursive_open_struct 1.0.0 → 1.0.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: 8d592a04a8b8f5f8bc0ff957c1b2575c84e9950b
4
- data.tar.gz: 31e1545862034248f907bb1d9805f4b864cdf845
3
+ metadata.gz: 0e47e061abf1c5d9daca2995714e188677fea62f
4
+ data.tar.gz: 03f821f35f28e32f1afebd56fec77e8a5d06a475
5
5
  SHA512:
6
- metadata.gz: 798a7bccdb299e99b0a21311cfcda1e5cda760ceca97cf59a5203c74114a7b9fc867a8cbef76d140206ba576ff1bb76c1ad27cb1a7483dbbc056aad0ebbb5222
7
- data.tar.gz: 837f57307351d32114725d0948cbacf566f5cc5def0897ea9825d28fdc120b445e180e07b53e9752c1725f9aa2f40b6bfd39ea512f1e72617dfe1286f7838d66
6
+ metadata.gz: 995a0373e906ab5a040cc69facdb612fa4ddfc08389496542643870e1d74677f64119b6b3178f6da993fb95d16e6b27d3008019113f3a2c43842a5fd20077bef
7
+ data.tar.gz: ec8418932147642a76483e864a0c59a7a78c472c0b0e4be18b5dfa0824d7829d8b1f4f92c0371c4480259d2a36c2ad5fdf5e54b724e040b87e39c59bd1d4cf4d
@@ -10,13 +10,7 @@ class SuperRecursiveOpenStruct
10
10
  RecursiveOpenStruct.new(hash, recurse_over_arrays: true)
11
11
  end
12
12
 
13
- if @raise_on_missing_methods
14
- @target.instance_eval do
15
- def method_missing(method, *_args)
16
- raise NoMethodError, "undefined method \`#{method}' for #{self.inspect}"
17
- end
18
- end
19
- end
13
+ patch_object(@target) if @raise_on_missing_methods
20
14
  end
21
15
 
22
16
  def method_missing(method, *args, &block)
@@ -35,4 +29,22 @@ class SuperRecursiveOpenStruct
35
29
  contents = @target.inspect.gsub(/\A#<RecursiveOpenStruct (.+)>\Z/, "\\1")
36
30
  "#<SuperRecursiveOpenStruct:0x#{__id__.to_s(16)} #{contents}>".freeze
37
31
  end
32
+
33
+ private def patch_object(object)
34
+ return unless object.respond_to?(:each_pair)
35
+
36
+ object.each_pair do |key, _|
37
+ child = object.public_send(key)
38
+
39
+ if child.respond_to?(:each_pair)
40
+ child.instance_eval do
41
+ def method_missing(method, *_args)
42
+ raise NoMethodError, "undefined method \`#{method}' for #{self.inspect}"
43
+ end
44
+ end
45
+
46
+ patch_object(child)
47
+ end
48
+ end
49
+ end
38
50
  end
@@ -14,8 +14,10 @@ describe SuperRecursiveOpenStruct do
14
14
  end
15
15
 
16
16
  it "does raise on missing methods" do
17
- sros = SuperRecursiveOpenStruct.new(a: 1)
17
+ sros = SuperRecursiveOpenStruct.new(a: { b: { c: 1 } })
18
18
  expect { sros.baz }.to raise_error(NoMethodError)
19
+ expect { sros.a.baz }.to raise_error(NoMethodError)
20
+ expect { sros.a.b.baz }.to raise_error(NoMethodError)
19
21
  end
20
22
 
21
23
  context "with raise_on_missing_methods = false" do
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "super_recursive_open_struct"
7
- spec.version = "1.0.0"
7
+ spec.version = "1.0.1"
8
8
  spec.authors = ["Cédric Félizard"]
9
9
  spec.email = ["cedric@felizard.fr"]
10
10
  spec.summary = %q{Like recursive-open-struct but slightly different}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_recursive_open_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric Félizard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: recursive-open-struct