recursive-open-struct 1.0.5 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ce4a65c03dbe16514c0c612776ec39b9a2c311b
4
- data.tar.gz: 3ff3fa9d5f9ebb3f9d51dd682102a1b78e1b426e
3
+ metadata.gz: 603694b270a6d4511c7154607cdb8d8c481f9c8b
4
+ data.tar.gz: 6c8f56108aefab75a7a1d3baeeb4a5963db1356d
5
5
  SHA512:
6
- metadata.gz: a3d79ba1465c421d5d0b0364b28b6bcc1b49d62e766e1aa7d2c5a1670a561e079808e32a2664bf055e654cf94bdb8fd53fe6a3c3087a4078c35c484d7b92d2d7
7
- data.tar.gz: 5fded05b30f636676539de9aaed356c735e9adb43fedc020691494ace3330eccb9ad78349646511a0a5b3164dabe91452e1e95d7263191ffdd12baa721ecc23e
6
+ metadata.gz: 8949632d753c57bfe7d5c191673346c1275d7805dbccf20a3ef52f03bd832b86d7755324b9b28728a9fddde09e004f20b13580693ce0e3dfaf4ef5cf239c5da4
7
+ data.tar.gz: 82f5fa6407b595972a9016995087d280b8136db3a9a64bc85b335dd316d52016e94b04b5db84682896ec8ad0f7994c63d02331a811abb710eb1de398c23749d6
@@ -4,13 +4,12 @@ rvm:
4
4
  # - 1.9.3 # json gem now requires Ruby ~> 2.0
5
5
  - 2.0.0
6
6
  - 2.1.10
7
- - 2.2.7
8
- - 2.3.4
9
- - 2.4.1
7
+ - 2.2.9
8
+ - 2.3.6
9
+ - 2.4.3
10
10
  - ruby-head
11
11
  - jruby-19mode
12
- - jruby-9.0.5.0
13
- - jruby-9.1.5.0
12
+ - jruby-9.1.9.0
14
13
  - jruby-head
15
14
  sudo: false
16
15
  matrix:
@@ -2,6 +2,7 @@ Recursive-open-struct was written by these fine people:
2
2
 
3
3
  * Beni Cherniavsky-Paskin <cben@redhat.com>
4
4
  * Cédric Felizard <cedric@felizard.fr>
5
+ * Edward Betts <edward@4angle.com>
5
6
  * Federico Aloi <federico.aloi@gmail.com>
6
7
  * fervic <roberto@runawaybit.com>
7
8
  * Joe Rafaniello <jrafanie@redhat.com>
@@ -1,3 +1,15 @@
1
+ 1.1.0 / 2018-02-03
2
+ ==================
3
+
4
+ * NEW/FIX [#56](https://github.com/aetherknight/recursive-open-struct/issues/56):
5
+ Add better support for Ruby 2.3+'s `#dig` method (when it exists for the
6
+ current version of Ruby), so that nested Hashes are properly converted to
7
+ RecursiveOpenStructs. `OpenStruct#dig`'s implementation was returning Hashes
8
+ and does not handle `recurse_over_arrays` so ROS needs special support.
9
+ Thanks to maxp-edcast for reporting the issue.
10
+ * FIX [#55](https://github.com/aetherknight/recursive-open-struct/pull/55):
11
+ EdwardBetts: Fixed a typo in the documentation/comment for `#method_missing`
12
+
1
13
  1.0.5 / 2017-06-21
2
14
  ==================
3
15
 
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2017, The Recursive-open-struct developers (given in the
1
+ Copyright (c) 2009-2018, The Recursive-open-struct developers (given in the
2
2
  file AUTHORS.txt).
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining
data/README.md CHANGED
@@ -64,5 +64,5 @@ clear, and concise, and well organized.
64
64
 
65
65
  ## Copyright
66
66
 
67
- Copyright (c) 2009-2017, The Recursive-open-struct developers (given in the
67
+ Copyright (c) 2009-2018, The Recursive-open-struct developers (given in the
68
68
  file AUTHORS.txt). See LICENSE.txt for details.
@@ -4,6 +4,7 @@ require 'recursive_open_struct/version'
4
4
  require 'recursive_open_struct/debug_inspect'
5
5
  require 'recursive_open_struct/deep_dup'
6
6
  require 'recursive_open_struct/ruby_19_backport'
7
+ require 'recursive_open_struct/dig'
7
8
 
8
9
  # TODO: When we care less about Rubies before 2.4.0, match OpenStruct's method
9
10
  # names instead of doing things like aliasing `new_ostruct_member` to
@@ -11,6 +12,7 @@ require 'recursive_open_struct/ruby_19_backport'
11
12
 
12
13
  class RecursiveOpenStruct < OpenStruct
13
14
  include Ruby19Backport if RUBY_VERSION =~ /\A1.9/
15
+ include Dig if OpenStruct.public_instance_methods.include? :dig
14
16
  include DebugInspect
15
17
 
16
18
  def initialize(hash=nil, args={})
@@ -66,7 +68,8 @@ class RecursiveOpenStruct < OpenStruct
66
68
  @table.key?(mname) || super
67
69
  end
68
70
 
69
- # Adapted implementation of method_missing to accomodate the differences between ROS and OS.
71
+ # Adapted implementation of method_missing to accommodate the differences
72
+ # between ROS and OS.
70
73
  #
71
74
  # TODO: Use modifiable? instead of modifiable, and new_ostruct_member!
72
75
  # instead of new_ostruct_member once we care less about Rubies before 2.4.0.
@@ -113,7 +116,7 @@ class RecursiveOpenStruct < OpenStruct
113
116
  # Support Ruby 2.4.0+'s changes in a way that doesn't require dynamically
114
117
  # modifying ROS.
115
118
  #
116
- # TODO: Once we care less about Rubies before 2.4.0, reverse this sot hat
119
+ # TODO: Once we care less about Rubies before 2.4.0, reverse this so that
117
120
  # new_ostruct_member points to our version and not OpenStruct's.
118
121
  alias new_ostruct_member! new_ostruct_member
119
122
  # new_ostruct_member! is private, but new_ostruct_member is not on OpenStruct in 2.4.0-rc1?!
@@ -0,0 +1,22 @@
1
+ class RecursiveOpenStruct < OpenStruct
2
+ module Dig
3
+
4
+ # Replaces +OpenStruct#dig+ to properly support treating nested values as
5
+ # RecursiveOpenStructs instead of returning the nested Hashes.
6
+ def dig(name, *names)
7
+ begin
8
+ name = name.to_sym
9
+ rescue NoMethodError
10
+ raise TypeError, "#{name} is not a symbol nor a string"
11
+ end
12
+
13
+ name_val = self[name]
14
+
15
+ if names.length > 0 && name_val.respond_to?(:dig)
16
+ name_val.dig(*names)
17
+ else
18
+ name_val
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,5 +3,5 @@
3
3
  require 'ostruct'
4
4
 
5
5
  class RecursiveOpenStruct < OpenStruct
6
- VERSION = "1.0.5"
6
+ VERSION = "1.1.0"
7
7
  end
@@ -6,7 +6,7 @@ describe RecursiveOpenStruct do
6
6
  let(:hash) { {:foo => 'foo', 'bar' => :bar} }
7
7
  subject(:ros) { RecursiveOpenStruct.new(hash) }
8
8
 
9
- describe "OpenStruct 2.0 methods" do
9
+ describe "OpenStruct 2.0+ methods" do
10
10
 
11
11
  context "Hash style setter" do
12
12
 
@@ -106,6 +106,6 @@ describe RecursiveOpenStruct do
106
106
  end
107
107
  end
108
108
 
109
- end
109
+ end # describe OpenStruct 2.0+ methods
110
110
 
111
111
  end
@@ -0,0 +1,49 @@
1
+ require_relative '../spec_helper'
2
+ require 'recursive_open_struct'
3
+
4
+ describe RecursiveOpenStruct do
5
+ describe "OpenStruct 2.3.0+ methods" do
6
+ describe "#dig" do
7
+ # We only care when Ruby supports `#dig`.
8
+ if OpenStruct.public_instance_methods.include? :dig
9
+ context "recurse_over_arrays: false" do
10
+ subject { RecursiveOpenStruct.new(a: { b: 2, c: ["doo", "bee", { inner: "one"}]}) }
11
+
12
+ describe "OpenStruct-like behavior" do
13
+ it { expect(subject.dig(:a, :b)).to eq 2 }
14
+ it { expect(subject.dig(:a, :c, 0)).to eq "doo" }
15
+ it { expect(subject.dig(:a, :c, 2, :inner)).to eq "one" }
16
+ end
17
+
18
+ describe "recursive behavior" do
19
+ it {
20
+ expect(subject.dig(:a)).to eq RecursiveOpenStruct.new(
21
+ { b: 2, c: ["doo", "bee", { inner: "one"}]}
22
+ )
23
+ }
24
+ it { expect(subject.dig(:a, :c, 2)).to eq({inner: "one"}) }
25
+ end
26
+ end
27
+
28
+ context "recurse_over_arrays: true" do
29
+ subject { RecursiveOpenStruct.new({a: { b: 2, c: ["doo", "bee", { inner: "one"}]}}, recurse_over_arrays: true) }
30
+
31
+ describe "OpenStruct-like behavior" do
32
+ it { expect(subject.dig(:a, :b)).to eq 2 }
33
+ it { expect(subject.dig(:a, :c, 0)).to eq "doo" }
34
+ it { expect(subject.dig(:a, :c, 2, :inner)).to eq "one" }
35
+ end
36
+
37
+ describe "recursive behavior" do
38
+ it {
39
+ expect(subject.dig(:a)).to eq RecursiveOpenStruct.new(
40
+ { b: 2, c: ["doo", "bee", { inner: "one"}]}
41
+ )
42
+ }
43
+ it { expect(subject.dig(:a, :c, 2)).to eq RecursiveOpenStruct.new(inner: "one") }
44
+ end
45
+ end
46
+ end
47
+ end # describe #dig
48
+ end # describe OpenStruct 2.3+ methods
49
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recursive-open-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William (B.J.) Snow Orvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2018-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,6 +127,7 @@ files:
127
127
  - lib/recursive_open_struct.rb
128
128
  - lib/recursive_open_struct/debug_inspect.rb
129
129
  - lib/recursive_open_struct/deep_dup.rb
130
+ - lib/recursive_open_struct/dig.rb
130
131
  - lib/recursive_open_struct/ruby_19_backport.rb
131
132
  - lib/recursive_open_struct/version.rb
132
133
  - recursive-open-struct.gemspec
@@ -134,6 +135,7 @@ files:
134
135
  - spec/recursive_open_struct/indifferent_access_spec.rb
135
136
  - spec/recursive_open_struct/open_struct_behavior_spec.rb
136
137
  - spec/recursive_open_struct/ostruct_2_0_0_spec.rb
138
+ - spec/recursive_open_struct/ostruct_2_3_0_spec.rb
137
139
  - spec/recursive_open_struct/recursion_and_subclassing_spec.rb
138
140
  - spec/recursive_open_struct/recursion_spec.rb
139
141
  - spec/spec_helper.rb
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  version: '0'
158
160
  requirements: []
159
161
  rubyforge_project:
160
- rubygems_version: 2.6.8
162
+ rubygems_version: 2.4.5.2
161
163
  signing_key:
162
164
  specification_version: 4
163
165
  summary: OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
@@ -166,6 +168,7 @@ test_files:
166
168
  - spec/recursive_open_struct/indifferent_access_spec.rb
167
169
  - spec/recursive_open_struct/open_struct_behavior_spec.rb
168
170
  - spec/recursive_open_struct/ostruct_2_0_0_spec.rb
171
+ - spec/recursive_open_struct/ostruct_2_3_0_spec.rb
169
172
  - spec/recursive_open_struct/recursion_and_subclassing_spec.rb
170
173
  - spec/recursive_open_struct/recursion_spec.rb
171
174
  - spec/spec_helper.rb