recursive-open-struct 1.1.0 → 1.1.1
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 +5 -5
- data/.travis.yml +12 -4
- data/AUTHORS.txt +3 -0
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTING.md +51 -0
- data/README.md +71 -28
- data/lib/recursive_open_struct.rb +21 -5
- data/lib/recursive_open_struct/version.rb +1 -1
- data/recursive-open-struct.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aef116134efc7102292ad51046c306be7e93621f688e02255996ca218ed578b1
|
4
|
+
data.tar.gz: 722c1e817dbdd25d4a48deb5923ce6f83de55211dd86c00a5c292f91e86bc74b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde1398adbd2795f9f108859d1d6c963a89048275be0fbf5e5cb1f92abb404ed8a55d4e97a8e2ba0d6367d3a255ecfdfe3dcfacc74d1b9bdd0d0c4e035acbe09
|
7
|
+
data.tar.gz: 82d16703403627ea358097b26d47334a984107c68a9c5360ac617169c4b9602292a7d7df77a96971ac3369fcca11256457518a61ce9895b7fcf9b58ab924c50b
|
data/.travis.yml
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
---
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
+
# No longer supported
|
4
5
|
# - 1.9.3 # json gem now requires Ruby ~> 2.0
|
5
6
|
- 2.0.0
|
6
7
|
- 2.1.10
|
7
|
-
- 2.2.
|
8
|
-
- 2.3.6
|
9
|
-
- 2.4.3
|
10
|
-
- ruby-head
|
8
|
+
- 2.2.10
|
11
9
|
- jruby-19mode
|
10
|
+
# Current stable supported by Travis
|
11
|
+
- 2.3.8
|
12
|
+
- 2.4.9
|
13
|
+
- 2.5.7
|
14
|
+
- 2.6.5
|
15
|
+
- 2.7.0
|
12
16
|
- jruby-9.1.9.0
|
17
|
+
# Future
|
18
|
+
- ruby-head
|
13
19
|
- jruby-head
|
14
20
|
sudo: false
|
15
21
|
matrix:
|
@@ -17,6 +23,8 @@ matrix:
|
|
17
23
|
# No longer supported
|
18
24
|
- rvm: 2.0.0
|
19
25
|
- rvm: 2.1.10
|
26
|
+
- rvm: 2.2.10
|
27
|
+
- rvm: 2.3.8
|
20
28
|
- rvm: jruby-19mode
|
21
29
|
# Future
|
22
30
|
- rvm: ruby-head
|
data/AUTHORS.txt
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
Recursive-open-struct was written by these fine people:
|
2
2
|
|
3
|
+
* Ben Langfeld <ben@langfeld.me>
|
3
4
|
* Beni Cherniavsky-Paskin <cben@redhat.com>
|
4
5
|
* Cédric Felizard <cedric@felizard.fr>
|
5
6
|
* Edward Betts <edward@4angle.com>
|
7
|
+
* Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
|
6
8
|
* Federico Aloi <federico.aloi@gmail.com>
|
7
9
|
* fervic <roberto@runawaybit.com>
|
8
10
|
* Joe Rafaniello <jrafanie@redhat.com>
|
@@ -12,6 +14,7 @@ Recursive-open-struct was written by these fine people:
|
|
12
14
|
* Offirmo <offirmo.net@gmail.com>
|
13
15
|
* Pedro Sena <sena.pedro@gmail.com>
|
14
16
|
* Peter Yeremenko <peter.yeremenko@gmail.com>
|
17
|
+
* Pirate Praveen <praveen@debian.org>
|
15
18
|
* Sebastian Gaul <sebastian@mgvmedia.com>
|
16
19
|
* Thiago Guimaraes <thiagogsr@gmail.com>
|
17
20
|
* Tom Chapin <tchapin@gmail.com>
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
1.1.1 / 2020/03/10
|
2
|
+
==================
|
3
|
+
|
4
|
+
* FIX [#64](https://github.com/aetherknight/recursive-open-struct/pull/64):
|
5
|
+
Pirate Praveen: Support Ruby 2.7.0. `OpenStruct#modifiable` support was
|
6
|
+
finally dropped, and has to be replaced with `OpenStruct#modifiable?`.
|
7
|
+
* Made some additional changes to continue supporting pre-2.4.x Rubies,
|
8
|
+
including the current stable JRuby (9.1.x.x, which tracks Ruby 2.3.x for
|
9
|
+
features)
|
10
|
+
|
1
11
|
1.1.0 / 2018-02-03
|
2
12
|
==================
|
3
13
|
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Contributing to recursive-open-struct
|
2
|
+
|
3
|
+
Thanks for wanting to contribute a bug or code to recursive-open-struct!
|
4
|
+
|
5
|
+
To help you out with understanding the direction and philosophy of this project
|
6
|
+
with regards to to new features/how it should behave (and whether to file a bug
|
7
|
+
report), please review the following contribution guidelines.
|
8
|
+
|
9
|
+
## ROS Feature Philosophy
|
10
|
+
|
11
|
+
Recursive-open-struct tries to be a minimal extension to the Ruby stdlib's
|
12
|
+
`ostruct`/OpenStruct that allows for a nested set of Hashes (and Arrays) to
|
13
|
+
initialize similarly structured OpenStruct-like objects. This has the benefit
|
14
|
+
of creating arbitrary objects whose values can be accessed with accessor
|
15
|
+
methods, similar to JavaScript Objects' dot-notation.
|
16
|
+
|
17
|
+
To phrase it another way, RecursiveOpenStruct tries to behave as closely as
|
18
|
+
possible to OpenStruct, except for the recursive functionality that it adds.
|
19
|
+
|
20
|
+
If Recursive-open-struct were to add additional features (particularly methods)
|
21
|
+
that are not implemented by OpenStruct, then those method names would not be
|
22
|
+
available for use for accessing fields with the dot-notation that OpenStruct
|
23
|
+
and RecursiveOpenStruct provide.
|
24
|
+
|
25
|
+
For example, OpenStruct is not (at the time this is written) a
|
26
|
+
subclass/specialization of Hash, so several methods implemented by Hash do not
|
27
|
+
work with OpenStruct (and thus Recursive OpenStruct), such as `#fetch`.
|
28
|
+
|
29
|
+
If you want to add features into RecursiveOpenStruct that would "pollute" the
|
30
|
+
method namespace more than OpenStruct already does, consider creating your own
|
31
|
+
subclass instead of submitting a code change to RecursiveOpenStruct itself.
|
32
|
+
|
33
|
+
|
34
|
+
## Filing/Fixing Bugs and Requesting/Proposing New Features
|
35
|
+
|
36
|
+
For simple bug fixes, feel free to provide a pull request. This includes bugs
|
37
|
+
in stated features of RecursiveOpenStruct, as well as features added to
|
38
|
+
OpenStruct in a newer version of Ruby that RecursiveOpenStruct needs custom
|
39
|
+
support to handle.
|
40
|
+
|
41
|
+
For anything else (new features, bugs that you want to report, and bugs that
|
42
|
+
are difficult to fix), I recommend opening an issue first to discuss the
|
43
|
+
feature or bug. I am fairly cautious about adding new features that might cause
|
44
|
+
RecursiveOpenStruct's API to deviate radically from OpenStruct's (since it
|
45
|
+
might introduce new reserved method names), and it is useful to discuss the
|
46
|
+
best way to solve a problem when there are tradeoffs or imperfect solutions.
|
47
|
+
|
48
|
+
When contributing code that changes behavior or fixes bugs, please include unit
|
49
|
+
tests to cover the new behavior or to provide regression testing for bugs.
|
50
|
+
Also, treat the unit tests as documentation --- make sure they are clean,
|
51
|
+
clear, and concise, and well organized.
|
data/README.md
CHANGED
@@ -3,64 +3,107 @@
|
|
3
3
|
OpenStruct subclass that returns nested hash attributes as
|
4
4
|
RecursiveOpenStructs.
|
5
5
|
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
6
9
|
It allows for hashes within hashes to be called in a chain of methods:
|
7
10
|
|
8
|
-
|
11
|
+
```ruby
|
12
|
+
ros = RecursiveOpenStruct.new( { wha: { tagoo: 'siam' } } )
|
9
13
|
|
10
|
-
|
14
|
+
ros.wha.tagoo # => 'siam'
|
15
|
+
```
|
11
16
|
|
12
17
|
Also, if needed, nested hashes can still be accessed as hashes:
|
13
18
|
|
14
|
-
|
19
|
+
```ruby
|
20
|
+
ros.wha_as_a_hash # { tagoo: 'siam' }
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
### Optional: Recurse Over Arrays
|
15
25
|
|
16
26
|
RecursiveOpenStruct can also optionally recurse across arrays, although you
|
17
|
-
have to explicitly enable it
|
27
|
+
have to explicitly enable it.
|
28
|
+
|
29
|
+
Default behavior:
|
30
|
+
```ruby
|
31
|
+
h = { :somearr => [ { name: 'a'}, { name: 'b' } ] }
|
32
|
+
|
33
|
+
ros = RecursiveOpenStruct.new(h)
|
34
|
+
ros.somearr # => [ { name: 'a'}, { name: 'b' } ]
|
35
|
+
```
|
36
|
+
|
37
|
+
Enabling `recurse_over_arrays`:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
ros = RecursiveOpenStruct.new(h, recurse_over_arrays: true )
|
41
|
+
|
42
|
+
ros.somearr[0].name # => 'a'
|
43
|
+
ros.somearr[1].name # => 'b'
|
44
|
+
```
|
18
45
|
|
19
|
-
h = { :somearr => [ { name: 'a'}, { name: 'b' } ] }
|
20
|
-
ros = RecursiveOpenStruct.new(h, recurse_over_arrays: true )
|
21
46
|
|
22
|
-
|
23
|
-
ros.somearr[1].name # => 'b'
|
47
|
+
### Optional: Preserve Original Keys
|
24
48
|
|
25
49
|
Also, by default it will turn all hash keys into symbols internally:
|
26
50
|
|
27
|
-
|
28
|
-
|
29
|
-
|
51
|
+
```ruby
|
52
|
+
h = { 'fear' => 'is', 'the' => 'mindkiller' } }
|
53
|
+
ros = RecursiveOpenStruct.new(h)
|
54
|
+
ros.to_h # => { fear: 'is', the: 'mindkiller' }
|
55
|
+
```
|
30
56
|
|
31
57
|
You can preserve the original keys by enabling `:preserve_original_keys`:
|
32
58
|
|
33
|
-
|
34
|
-
|
35
|
-
|
59
|
+
```ruby
|
60
|
+
h = { 'fear' => 'is', 'the' => 'mindkiller' } }
|
61
|
+
ros = RecursiveOpenStruct.new(h, preserve_original_keys: true)
|
62
|
+
ros.to_h # => { 'fear' => 'is', 'the' => 'mindkiller' }
|
63
|
+
```
|
64
|
+
|
36
65
|
|
37
66
|
## Installation
|
38
67
|
|
39
68
|
Available as a gem in rubygems, the default gem repository.
|
40
69
|
|
41
|
-
If you use bundler, just
|
70
|
+
If you use bundler, just add recursive-open-struct to your gemfile :
|
42
71
|
|
43
|
-
|
72
|
+
```ruby
|
73
|
+
gem 'recursive-open-struct'
|
74
|
+
```
|
44
75
|
|
45
|
-
You may also install the gem manually
|
76
|
+
You may also install the gem manually:
|
46
77
|
|
47
78
|
gem install recursive-open-struct
|
48
79
|
|
80
|
+
|
49
81
|
## Contributing
|
50
82
|
|
51
|
-
|
83
|
+
If you would like to file or fix a bug, or propose a new feature, please review
|
84
|
+
[CONTRIBUTING](CONTRIBUTING.md) first.
|
85
|
+
|
86
|
+
|
87
|
+
## Supported Ruby Versions
|
88
|
+
|
89
|
+
Recursive-open-struct attempts to support just the versions of Ruby that are
|
90
|
+
still actively maintained. Once a given major/minor version of Ruby no longer
|
91
|
+
receives patches, they will no longer be supported (but recursive-open-struct
|
92
|
+
may still work). I usually update the travis.yml file to reflect this when
|
93
|
+
preparing for a new release or do some other work on recursive-open-struct.
|
94
|
+
|
95
|
+
I also try to update recursive-open-struct to support new features in
|
96
|
+
OpenStruct itself as new versions of Ruby are released. However, I don't
|
97
|
+
actively monitor the status of this, so a newer feature might not work. If you
|
98
|
+
encounter such a feature, please file a bug or a PR to fix it, and I will try
|
99
|
+
to cut a new release of recursive-open-struct quickly.
|
100
|
+
|
101
|
+
|
102
|
+
## SemVer Compliance
|
52
103
|
|
53
|
-
|
54
|
-
|
55
|
-
feature or bug. I am fairly cautious about adding new features that might cause
|
56
|
-
RecursiveOpenStruct's API to deviate radically from OpenStruct's (since it
|
57
|
-
might introduce new reserved method names), and it is useful to discuss the
|
58
|
-
best way to solve a problem when there are tradeoffs or imperfect solutions.
|
104
|
+
Rescursive-open-struct follows [SemVer
|
105
|
+
2.0](https://semver.org/spec/v2.0.0.html) for its versioning.
|
59
106
|
|
60
|
-
When contributing code that changes behavior or fixes bugs, please include unit
|
61
|
-
tests to cover the new behavior or to provide regression testing for bugs.
|
62
|
-
Also, treat the unit tests as documentation --- make sure they are clean,
|
63
|
-
clear, and concise, and well organized.
|
64
107
|
|
65
108
|
## Copyright
|
66
109
|
|
@@ -9,10 +9,16 @@ require 'recursive_open_struct/dig'
|
|
9
9
|
# TODO: When we care less about Rubies before 2.4.0, match OpenStruct's method
|
10
10
|
# names instead of doing things like aliasing `new_ostruct_member` to
|
11
11
|
# `new_ostruct_member!`
|
12
|
+
#
|
13
|
+
# TODO: `#*_as_a_hash` deprecated. Nested hashes can be referenced using
|
14
|
+
# `#to_h`.
|
12
15
|
|
13
16
|
class RecursiveOpenStruct < OpenStruct
|
14
17
|
include Ruby19Backport if RUBY_VERSION =~ /\A1.9/
|
15
18
|
include Dig if OpenStruct.public_instance_methods.include? :dig
|
19
|
+
|
20
|
+
# TODO: deprecated, possibly remove or make optional an runtime so that it
|
21
|
+
# doesn't normally pollute the public method namespace
|
16
22
|
include DebugInspect
|
17
23
|
|
18
24
|
def initialize(hash=nil, args={})
|
@@ -42,6 +48,8 @@ class RecursiveOpenStruct < OpenStruct
|
|
42
48
|
@deep_dup.call(@table)
|
43
49
|
end
|
44
50
|
|
51
|
+
# TODO: deprecated, unsupported by OpenStruct. OpenStruct does not consider
|
52
|
+
# itself to be a "kind of" Hash.
|
45
53
|
alias_method :to_hash, :to_h
|
46
54
|
|
47
55
|
def [](name)
|
@@ -68,18 +76,26 @@ class RecursiveOpenStruct < OpenStruct
|
|
68
76
|
@table.key?(mname) || super
|
69
77
|
end
|
70
78
|
|
79
|
+
# Continue supporting older rubies -- JRuby 9.1.x.x is still considered
|
80
|
+
# stable, but is based on Ruby
|
81
|
+
# 2.3.x and so uses :modifiable instead of :modifiable?. Furthermore, if
|
82
|
+
# :modifiable is private, then make :modifiable? private too.
|
83
|
+
if !OpenStruct.private_instance_methods.include?(:modifiable?)
|
84
|
+
alias_method :modifiable?, :modifiable
|
85
|
+
if OpenStruct.private_instance_methods.include?(:modifiable)
|
86
|
+
private :modifiable?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
71
90
|
# Adapted implementation of method_missing to accommodate the differences
|
72
91
|
# between ROS and OS.
|
73
|
-
#
|
74
|
-
# TODO: Use modifiable? instead of modifiable, and new_ostruct_member!
|
75
|
-
# instead of new_ostruct_member once we care less about Rubies before 2.4.0.
|
76
92
|
def method_missing(mid, *args)
|
77
93
|
len = args.length
|
78
94
|
if mid =~ /^(.*)=$/
|
79
95
|
if len != 1
|
80
96
|
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
|
81
97
|
end
|
82
|
-
modifiable[new_ostruct_member!($1.to_sym)] = args[0]
|
98
|
+
modifiable?[new_ostruct_member!($1.to_sym)] = args[0]
|
83
99
|
elsif len == 0
|
84
100
|
key = mid
|
85
101
|
key = $1 if key =~ /^(.*)_as_a_hash$/
|
@@ -105,7 +121,7 @@ class RecursiveOpenStruct < OpenStruct
|
|
105
121
|
end
|
106
122
|
define_method("#{name}=") do |x|
|
107
123
|
@sub_elements.delete(key_name)
|
108
|
-
modifiable[key_name] = x
|
124
|
+
modifiable?[key_name] = x
|
109
125
|
end
|
110
126
|
define_method("#{name}_as_a_hash") { @table[key_name] }
|
111
127
|
end
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["William (B.J.) Snow Orvis"]
|
9
9
|
s.email = "aetherknight@gmail.com"
|
10
10
|
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
11
|
-
s.homepage = "
|
11
|
+
s.homepage = "https://github.com/aetherknight/recursive-open-struct"
|
12
12
|
s.licenses = ["MIT"]
|
13
13
|
|
14
14
|
s.summary = "OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs"
|
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.1.
|
4
|
+
version: 1.1.1
|
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: 2020-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- ".travis.yml"
|
120
120
|
- AUTHORS.txt
|
121
121
|
- CHANGELOG.md
|
122
|
+
- CONTRIBUTING.md
|
122
123
|
- Gemfile
|
123
124
|
- LICENSE.txt
|
124
125
|
- README.md
|
@@ -139,7 +140,7 @@ files:
|
|
139
140
|
- spec/recursive_open_struct/recursion_and_subclassing_spec.rb
|
140
141
|
- spec/recursive_open_struct/recursion_spec.rb
|
141
142
|
- spec/spec_helper.rb
|
142
|
-
homepage:
|
143
|
+
homepage: https://github.com/aetherknight/recursive-open-struct
|
143
144
|
licenses:
|
144
145
|
- MIT
|
145
146
|
metadata: {}
|
@@ -158,8 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
- !ruby/object:Gem::Version
|
159
160
|
version: '0'
|
160
161
|
requirements: []
|
161
|
-
|
162
|
-
rubygems_version: 2.4.5.2
|
162
|
+
rubygems_version: 3.1.2
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
|