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 +4 -4
- data/.travis.yml +4 -5
- data/AUTHORS.txt +1 -0
- data/CHANGELOG.md +12 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/recursive_open_struct.rb +5 -2
- data/lib/recursive_open_struct/dig.rb +22 -0
- data/lib/recursive_open_struct/version.rb +1 -1
- data/spec/recursive_open_struct/ostruct_2_0_0_spec.rb +2 -2
- data/spec/recursive_open_struct/ostruct_2_3_0_spec.rb +49 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 603694b270a6d4511c7154607cdb8d8c481f9c8b
|
4
|
+
data.tar.gz: 6c8f56108aefab75a7a1d3baeeb4a5963db1356d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8949632d753c57bfe7d5c191673346c1275d7805dbccf20a3ef52f03bd832b86d7755324b9b28728a9fddde09e004f20b13580693ce0e3dfaf4ef5cf239c5da4
|
7
|
+
data.tar.gz: 82f5fa6407b595972a9016995087d280b8136db3a9a64bc85b335dd316d52016e94b04b5db84682896ec8ad0f7994c63d02331a811abb710eb1de398c23749d6
|
data/.travis.yml
CHANGED
@@ -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.
|
8
|
-
- 2.3.
|
9
|
-
- 2.4.
|
7
|
+
- 2.2.9
|
8
|
+
- 2.3.6
|
9
|
+
- 2.4.3
|
10
10
|
- ruby-head
|
11
11
|
- jruby-19mode
|
12
|
-
- jruby-9.
|
13
|
-
- jruby-9.1.5.0
|
12
|
+
- jruby-9.1.9.0
|
14
13
|
- jruby-head
|
15
14
|
sudo: false
|
16
15
|
matrix:
|
data/AUTHORS.txt
CHANGED
@@ -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>
|
data/CHANGELOG.md
CHANGED
@@ -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
|
|
data/LICENSE.txt
CHANGED
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-
|
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
|
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
|
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
|
@@ -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
|
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:
|
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.
|
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
|