recursive-open-struct 1.0.2 → 1.0.3

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: 12d07e25ed0f3cedb3b40ede9f61407ea53a9927
4
- data.tar.gz: a485cfb540bfb5bd8c91c423e51d54178667c43d
3
+ metadata.gz: 1a818135247a6ccee4084c02a5504a41213ed7ef
4
+ data.tar.gz: 83e7f427a585d6b32f0d041d0b237e37f16fc7d1
5
5
  SHA512:
6
- metadata.gz: 6e15e67bbc323ae60734aebe7a5f124c35ff96b22589ec295c8a6e374390ba9b869e9e34f0f1b04c5079853b950e77f0cdbb5b55933ce908f8bf66b012c23a65
7
- data.tar.gz: 2d1466d7c584cf5d969ab5ae49ba5c79f17ef85fd86001e56ecac64e0317c92449c87b89dfc6d20ac4b7c372a6bc0eb560b8d3b44e942ba02d0810fc3f660fe8
6
+ metadata.gz: 786b9589759c155996647a4a5cf35ae3d3bb28515c9d6cc9555ca152c4ff34578abb8b6e3357b5711340f22702e482517ad8d60d5fd53c0f418f99caa95d819a
7
+ data.tar.gz: e76b6ab3dc483c8eecbcc40cfae8f66da581533d45826d7e215baaf763f6f6176bb040502c96f2858c4492ca93784d1de302ed78eb9417abf3efb357129970dc
@@ -1,13 +1,24 @@
1
1
  ---
2
2
  language: ruby
3
3
  rvm:
4
+ # - 1.9.3 # json gem now requires Ruby ~> 2.0
4
5
  - 2.0.0
5
6
  - 2.1.10
6
- - 2.2.5
7
- - 2.3.1
8
- - 2.4.0
7
+ - 2.2.7
8
+ - 2.3.4
9
+ - 2.4.1
9
10
  - ruby-head
10
11
  - jruby-19mode
11
12
  - jruby-9.0.5.0
13
+ - jruby-9.1.5.0
12
14
  - jruby-head
13
15
  sudo: false
16
+ matrix:
17
+ allow_failures:
18
+ # No longer supported
19
+ - rvm: 2.0.0
20
+ - rvm: 2.1.10
21
+ - rvm: jruby-19mode
22
+ # Future
23
+ - rvm: ruby-head
24
+ - rvm: jruby-head
@@ -1,3 +1,21 @@
1
+ 1.0.3 / 2017-04-10
2
+ ==================
3
+
4
+ * No longer officially supporting Ruby 2.0.0 and Ruby 2.1.x. They are still
5
+ tested against but are permitted to fail within the Travis configuration.
6
+ * FIX: Fix subscript notation for keys that collide with existing public
7
+ methods. Related to
8
+ [#51](https://github.com/aetherknight/recursive-open-struct/issues/51).
9
+ * FIX [#49](https://github.com/aetherknight/recursive-open-struct/issues/49):
10
+ Ensure test suite passes with Ruby 2.4.0-rc1.
11
+
12
+ 1.0.2 / 2016-12-20
13
+ ==================
14
+
15
+ * FIX [#46](https://github.com/aetherknight/recursive-open-struct/issues/46):
16
+ Pedro Sena: fix issues with mutating arrays within an ROS that has
17
+ `recurse_over_arrays: true`
18
+
1
19
  1.0.1 / 2016-01-18
2
20
  ==================
3
21
 
@@ -5,6 +5,10 @@ require 'recursive_open_struct/debug_inspect'
5
5
  require 'recursive_open_struct/deep_dup'
6
6
  require 'recursive_open_struct/ruby_19_backport'
7
7
 
8
+ # TODO: When we care less about Rubies before 2.4.0, match OpenStruct's method
9
+ # names instead of doing things like aliasing `new_ostruct_member` to
10
+ # `new_ostruct_member!`
11
+
8
12
  class RecursiveOpenStruct < OpenStruct
9
13
  include Ruby19Backport if RUBY_VERSION =~ /\A1.9/
10
14
  include DebugInspect
@@ -39,7 +43,21 @@ class RecursiveOpenStruct < OpenStruct
39
43
  alias_method :to_hash, :to_h
40
44
 
41
45
  def [](name)
42
- public_send(name)
46
+ key_name = _get_key_from_table_(name)
47
+ v = @table[key_name]
48
+ if v.is_a?(Hash)
49
+ @sub_elements[key_name] ||= self.class.new(
50
+ v,
51
+ recurse_over_arrays: @recurse_over_arrays,
52
+ preserve_original_keys: @preserve_original_keys,
53
+ mutate_input_hash: true
54
+ )
55
+ elsif v.is_a?(Array) and @recurse_over_arrays
56
+ @sub_elements[key_name] ||= recurse_over_array(v)
57
+ @sub_elements[key_name] = recurse_over_array(@sub_elements[key_name])
58
+ else
59
+ v
60
+ end
43
61
  end
44
62
 
45
63
  # Makes sure ROS responds as expected on #respond_to? and #method requests
@@ -49,18 +67,21 @@ class RecursiveOpenStruct < OpenStruct
49
67
  end
50
68
 
51
69
  # Adapted implementation of method_missing to accomodate the differences between ROS and OS.
70
+ #
71
+ # TODO: Use modifiable? instead of modifiable, and new_ostruct_member!
72
+ # instead of new_ostruct_member once we care less about Rubies before 2.4.0.
52
73
  def method_missing(mid, *args)
53
74
  len = args.length
54
75
  if mid =~ /^(.*)=$/
55
76
  if len != 1
56
77
  raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
57
78
  end
58
- modifiable[new_ostruct_member($1.to_sym)] = args[0]
79
+ modifiable[new_ostruct_member!($1.to_sym)] = args[0]
59
80
  elsif len == 0
60
81
  key = mid
61
82
  key = $1 if key =~ /^(.*)_as_a_hash$/
62
83
  if @table.key?(_get_key_from_table_(key))
63
- new_ostruct_member(key)
84
+ new_ostruct_member!(key)
64
85
  send(mid)
65
86
  end
66
87
  else
@@ -70,25 +91,14 @@ class RecursiveOpenStruct < OpenStruct
70
91
  end
71
92
  end
72
93
 
94
+ # TODO: Rename to new_ostruct_member! once we care less about Rubies before
95
+ # 2.4.0.
73
96
  def new_ostruct_member(name)
74
- key_name = _get_key_from_table_ name
97
+ key_name = _get_key_from_table_(name)
75
98
  unless self.methods.include?(name.to_sym)
76
99
  class << self; self; end.class_eval do
77
100
  define_method(name) do
78
- v = @table[key_name]
79
- if v.is_a?(Hash)
80
- @sub_elements[key_name] ||= self.class.new(
81
- v,
82
- recurse_over_arrays: @recurse_over_arrays,
83
- preserve_original_keys: @preserve_original_keys,
84
- mutate_input_hash: true
85
- )
86
- elsif v.is_a?(Array) and @recurse_over_arrays
87
- @sub_elements[key_name] ||= recurse_over_array(v)
88
- @sub_elements[key_name] = recurse_over_array(@sub_elements[key_name])
89
- else
90
- v
91
- end
101
+ self[key_name]
92
102
  end
93
103
  define_method("#{name}=") do |x|
94
104
  @sub_elements.delete(key_name)
@@ -100,6 +110,15 @@ class RecursiveOpenStruct < OpenStruct
100
110
  key_name
101
111
  end
102
112
 
113
+ # Support Ruby 2.4.0+'s changes in a way that doesn't require dynamically
114
+ # modifying ROS.
115
+ #
116
+ # TODO: Once we care less about Rubies before 2.4.0, reverse this sot hat
117
+ # new_ostruct_member points to our version and not OpenStruct's.
118
+ alias new_ostruct_member! new_ostruct_member
119
+ # new_ostruct_member! is private, but new_ostruct_member is not on OpenStruct in 2.4.0-rc1?!
120
+ private :new_ostruct_member!
121
+
103
122
  def delete_field(name)
104
123
  sym = _get_key_from_table_(name)
105
124
  singleton_class.__send__(:remove_method, sym, "#{sym}=") rescue NoMethodError # ignore if methods not yet generated.
@@ -118,7 +137,7 @@ class RecursiveOpenStruct < OpenStruct
118
137
  def recurse_over_array(array)
119
138
  array.each_with_index do |a, i|
120
139
  if a.is_a? Hash
121
- array[i] = self.class.new(a, :recurse_over_arrays => true,
140
+ array[i] = self.class.new(a, :recurse_over_arrays => true,
122
141
  :mutate_input_hash => true, :preserve_original_keys => @preserve_original_keys)
123
142
  elsif a.is_a? Array
124
143
  array[i] = recurse_over_array a
@@ -3,5 +3,5 @@
3
3
  require 'ostruct'
4
4
 
5
5
  class RecursiveOpenStruct < OpenStruct
6
- VERSION = "1.0.2"
6
+ VERSION = "1.0.3"
7
7
  end
@@ -63,6 +63,26 @@ describe RecursiveOpenStruct do
63
63
  expect(ros.test).to eq :foo
64
64
  expect(ros.rand).to eq 'not a number'
65
65
  end
66
+
67
+ end
68
+
69
+ context 'that contains keys that mirror existing public methods inherited from Object' do
70
+ let(:hash) { { method: :something } }
71
+ it 'handles subscript notation without calling the existing methods' do
72
+ expect(ros[:method]).to eq :something
73
+ expect(ros['method']).to eq :something
74
+ end
75
+ end
76
+
77
+ if [/\A([0-9]+)\.([0-9]+)\.([0-9]+)\z/.match(RUBY_VERSION)].tap { |l| m = l[0] ; l[0] = (m[1].to_i >= 2 && m[2].to_i >= 4) }.first
78
+ context 'when Ruby 2.4.0 or newer' do
79
+ specify 'new_ostruct_member! is private' do
80
+ expect {
81
+ ros.new_ostruct_member!(:bonsoir)
82
+ }.to raise_error(NoMethodError)
83
+ # OpenStruct.new().new_ostruct_member!(:foo)
84
+ end
85
+ end
66
86
  end
67
87
 
68
88
  end
metadata CHANGED
@@ -1,94 +1,94 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recursive-open-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William (B.J.) Snow Orvis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-19 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '0'
20
- type: :development
19
+ name: bundler
21
20
  prerelease: false
21
+ type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: pry
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
- type: :development
33
+ name: pry
35
34
  prerelease: false
35
+ type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - ">="
46
45
  - !ruby/object:Gem::Version
47
46
  version: '0'
48
- type: :development
47
+ name: rake
49
48
  prerelease: false
49
+ type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rdoc
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
62
- type: :development
61
+ name: rdoc
63
62
  prerelease: false
63
+ type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - "~>"
74
73
  - !ruby/object:Gem::Version
75
74
  version: '3.2'
76
- type: :development
75
+ name: rspec
77
76
  prerelease: false
77
+ type: :development
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.2'
83
83
  - !ruby/object:Gem::Dependency
84
- name: simplecov
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - ">="
88
87
  - !ruby/object:Gem::Version
89
88
  version: '0'
90
- type: :development
89
+ name: simplecov
91
90
  prerelease: false
91
+ type: :development
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
@@ -141,7 +141,7 @@ homepage: http://github.com/aetherknight/recursive-open-struct
141
141
  licenses:
142
142
  - MIT
143
143
  metadata: {}
144
- post_install_message:
144
+ post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths:
147
147
  - lib
@@ -156,9 +156,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.5.1
161
- signing_key:
159
+ rubyforge_project:
160
+ rubygems_version: 2.6.6
161
+ signing_key:
162
162
  specification_version: 4
163
163
  summary: OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
164
164
  test_files: