recursive_struct 0.0.4 → 0.0.5
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 +8 -8
- data/README.md +2 -2
- data/lib/recursive_struct.rb +6 -0
- data/lib/recursive_struct/version.rb +1 -1
- data/spec/recursive_struct_spec.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2UxYTExZjRiNjU2YjY2ZmE4ZTA0OTFhMDcyYjIzMGRiMjFhZTRhNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjA2M2I0ZDljNjAwM2UwM2MwNWE1NjY5MDIyZmRkZjQ4NDM4OWZjMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTBlNzY4MmVhNDJjMWJiOTQyYjI3ZThjYmUzNjI2ZTBhOTczZTk3M2JlNjkz
|
10
|
+
MzYzYmUyMjk0ZjhhMmJjY2ZjZjA1MzMyYjczNWY4NmZmYzM1NjM3MjIxYTk0
|
11
|
+
MDU3NmM3ZDBmMmJiN2E0NWQ0OTI4YjFkZDNhNWNmMTRkODY1ZTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjY5ZjczNGRkZmQwYjg1ZTlhMDQwYzMxNzI5MzFjYTNmMWY4NDQ1ODQ4MTY2
|
14
|
+
YTYyNmFjNjAxYTUwMDA1NzcxNzc5ZTNkZTFmYTg2ZmRjMTYzMTMyZDhmNDJj
|
15
|
+
MTBiMzhhZTRjMTFkYWVhMDlkZDM0NTU0OWZiNTI4Njk2NzQ0NzM=
|
data/README.md
CHANGED
@@ -29,14 +29,14 @@ struct.a.b # true
|
|
29
29
|
struct.c # false
|
30
30
|
```
|
31
31
|
|
32
|
-
You can also
|
32
|
+
You can also use a setter for a method that doesn't exist. A getter and setter will be generated dynamically.
|
33
33
|
```
|
34
34
|
struct = RecursiveStruct.new
|
35
35
|
struct.a = true
|
36
36
|
struct.a # true
|
37
37
|
```
|
38
38
|
|
39
|
-
If this value happens to be a hash, it will
|
39
|
+
If this value happens to be a hash, it will be wrapped in a RecursiveStruct.
|
40
40
|
```
|
41
41
|
struct = RecursiveStruct.new
|
42
42
|
struct.a = { b: true }
|
data/lib/recursive_struct.rb
CHANGED
@@ -12,6 +12,8 @@ class RecursiveStruct
|
|
12
12
|
|
13
13
|
if key.chomp!('=') && args.length == 1
|
14
14
|
add_data(key, process(args.first))
|
15
|
+
elsif args.length == 0
|
16
|
+
get_data(key)
|
15
17
|
else
|
16
18
|
super(name, *args)
|
17
19
|
end
|
@@ -34,6 +36,10 @@ class RecursiveStruct
|
|
34
36
|
define_methods(key)
|
35
37
|
end
|
36
38
|
|
39
|
+
def get_data(key)
|
40
|
+
data[key.to_sym]
|
41
|
+
end
|
42
|
+
|
37
43
|
def define_methods(key)
|
38
44
|
unless respond_to?(key)
|
39
45
|
define_singleton_method(key) { data[key] }
|
@@ -65,8 +65,12 @@ describe RecursiveStruct do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
describe 'invalid getter' do
|
69
|
+
it { expect(subject.one).to be_nil }
|
70
|
+
end
|
71
|
+
|
68
72
|
describe 'invalid method' do
|
69
|
-
it { expect { subject.one }.to raise_error NoMethodError }
|
73
|
+
it { expect { subject.one(1) }.to raise_error NoMethodError }
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recursive_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phillip Boksz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|