libis-tools 0.9.3 → 0.9.4

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: e2c6c77cfccd6c062ae90c8379432fddc206f414
4
- data.tar.gz: 215cea5196e3827cd404b1e4152aeb31ef526e36
3
+ metadata.gz: fa31aed0ec4adc0f57dcca3d2f816261a0ee956b
4
+ data.tar.gz: 5d7713ea273850ba3050c6150377d42987a5daea
5
5
  SHA512:
6
- metadata.gz: 166dbb502d7ddb353711dd3ca89566e054f2c0f10c47295c10bb20a869dd645ad41c7211a1682f2d995492e120b0dfcdf3c0584b77678a0aa1647a6913072db0
7
- data.tar.gz: c8ddc3e402ae7b7e4a0671e1619d73da0c276b40ffbd9c1be824f4e6e07e644191b20b85e1379d4213accde18fad2a3f5e9699cb57d5d575bcc15a4e51f772e4
6
+ metadata.gz: 7e6d7eb3379ca0ba55f5730a8e1b96b7170e206ee10b38dcea7ff6a18861b854b4a534ec7ed7069f553be36b7d86b6d6d2ed5923a8c50518057e3386c6a5ee20
7
+ data.tar.gz: 8e8d4cb03b0018ed90beb10fe78d538a95aa34455906018b92cfa2b0218296cc8a9d582a1a046f950be818d89ccd36b3caaa59dde30ac6d9a294622b46091c9a
@@ -0,0 +1,15 @@
1
+ require 'libis/tools/extend/ostruct'
2
+ require 'recursive-open-struct'
3
+
4
+ module Libis
5
+ module Tools
6
+ class DeepStruct < RecursiveOpenStruct
7
+
8
+ def initialize(hash = {}, opts = {})
9
+ hash = {default: hash} unless hash.is_a? Hash
10
+ super(hash, {recurse_over_arrays: true}.merge(opts))
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -34,6 +34,10 @@ class Hash
34
34
  end
35
35
  end unless method_defined? :recursive_merge!
36
36
 
37
+ def key_strings_to_symbols!(opts = {})
38
+ self.replace self.key_strings_to_symbols opts
39
+ end unless method_defined? :key_strings_to_symbols!
40
+
37
41
  def key_strings_to_symbols(opts = {})
38
42
  opts = {resursive: false, upcase: false, downcase: false}.merge opts
39
43
 
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Tools
3
- VERSION = '0.9.3'
3
+ VERSION = '0.9.4'
4
4
  end
5
5
  end
data/libis-tools.gemspec CHANGED
@@ -30,10 +30,12 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'simplecov', '~> 0.9'
31
31
  spec.add_development_dependency 'equivalent-xml', '~> 0.5'
32
32
 
33
+
33
34
  spec.add_runtime_dependency 'backports', '~> 3.6'
34
35
  spec.add_runtime_dependency 'savon', '~> 2.0'
35
36
  spec.add_runtime_dependency 'nokogiri', '~> 1.6'
36
37
  spec.add_runtime_dependency 'gyoku', '~> 1.2'
37
38
  spec.add_runtime_dependency 'nori', '~> 2.4'
39
+ spec.add_runtime_dependency 'recursive-open-struct', '~>0.6'
38
40
 
39
41
  end
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ require_relative 'spec_helper'
3
+ require 'libis/tools/deep_struct'
4
+
5
+ describe 'DeepStruct' do
6
+
7
+ hash = {a: 1, 'b' => '2', c: 3.0}
8
+ recursive_hash = {
9
+ a: {x: 0, y: 0, z: 0},
10
+ b: {x: 10, y: -5, z: 2.5},
11
+ c: [
12
+ [
13
+ {a: 1},
14
+ {a: 2}
15
+ ]
16
+ ]
17
+ }
18
+
19
+ it 'should initialize' do
20
+ ds = Libis::Tools::DeepStruct.new
21
+ expect(ds).not_to eq nil
22
+ end
23
+
24
+ # noinspection RubyResolve
25
+ it 'should store Hash values' do
26
+ ds = Libis::Tools::DeepStruct.new hash
27
+ expect(ds[:a]).to eq 1
28
+ expect(ds[:b]).to eq '2'
29
+ expect(ds[:c]).to eq 3.0
30
+ end
31
+
32
+ it 'should allow access through methods' do
33
+ ds = Libis::Tools::DeepStruct.new hash
34
+ expect(ds.a).to eq 1
35
+ expect(ds.b).to eq '2'
36
+ expect(ds.c).to eq 3.0
37
+ end
38
+
39
+ it 'should allow access through methods, key strings and key symbols' do
40
+ ds = Libis::Tools::DeepStruct.new hash
41
+ expect(ds.a).to eq 1
42
+ expect(ds.b).to eq '2'
43
+ expect(ds.c).to eq 3.0
44
+
45
+ expect(ds['a']).to eq 1
46
+ expect(ds['b']).to eq '2'
47
+ expect(ds['c']).to eq 3.0
48
+
49
+ expect(ds[:a]).to eq 1
50
+ expect(ds[:b]).to eq '2'
51
+ expect(ds[:c]).to eq 3.0
52
+
53
+ expect(ds.b).to be ds[:b]
54
+ expect(ds.b).to be ds['b']
55
+
56
+ end
57
+
58
+ it 'should store non-hashes with :default key' do
59
+ ds = Libis::Tools::DeepStruct.new 'abc'
60
+ expect(ds[:default]).to eq 'abc'
61
+ end
62
+
63
+ it 'should store recursive Hashes as DeepStructs' do
64
+ ds = Libis::Tools::DeepStruct.new(recursive_hash)
65
+ expect(ds[:a]).to be_a Libis::Tools::DeepStruct
66
+ expect(ds.b).to be_a Libis::Tools::DeepStruct
67
+ end
68
+
69
+ it 'should recurse over arrays by default' do
70
+ ds = Libis::Tools::DeepStruct.new(recursive_hash)
71
+ expect(ds.c[0][0]).to be_a Libis::Tools::DeepStruct
72
+ expect(ds.c.first.first.a).to eq 1
73
+ expect(ds.c.first[1].a).to eq 2
74
+ end
75
+
76
+ it 'should deliver hashes if asked' do
77
+ ds = Libis::Tools::DeepStruct.new(recursive_hash)
78
+ expect(ds.to_h).to eq recursive_hash
79
+ expect(ds.b.to_h).to eq recursive_hash[:b]
80
+ end
81
+
82
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2.4'
153
+ - !ruby/object:Gem::Dependency
154
+ name: recursive-open-struct
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.6'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.6'
153
167
  description: Some tool classes for other LIBIS gems.
154
168
  email:
155
169
  - kris.dekeyser@libis.be
@@ -172,6 +186,7 @@ files:
172
186
  - lib/libis/tools/command.rb
173
187
  - lib/libis/tools/config.rb
174
188
  - lib/libis/tools/dc_record.rb
189
+ - lib/libis/tools/deep_struct.rb
175
190
  - lib/libis/tools/extend/empty.rb
176
191
  - lib/libis/tools/extend/hash.rb
177
192
  - lib/libis/tools/extend/ostruct.rb
@@ -192,6 +207,7 @@ files:
192
207
  - spec/data/test.data
193
208
  - spec/data/test.xml
194
209
  - spec/data/test.yml
210
+ - spec/deep_struct_spec.rb
195
211
  - spec/logger_spec.rb
196
212
  - spec/parameter_container_spec.rb
197
213
  - spec/parameter_spec.rb
@@ -233,6 +249,7 @@ test_files:
233
249
  - spec/data/test.data
234
250
  - spec/data/test.xml
235
251
  - spec/data/test.yml
252
+ - spec/deep_struct_spec.rb
236
253
  - spec/logger_spec.rb
237
254
  - spec/parameter_container_spec.rb
238
255
  - spec/parameter_spec.rb