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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTg4ZDBlM2U1ZjhhZGFhNDU1MTY0YTc2YmRhYjM1YWIxMmNiYTI5Yg==
4
+ N2UxYTExZjRiNjU2YjY2ZmE4ZTA0OTFhMDcyYjIzMGRiMjFhZTRhNQ==
5
5
  data.tar.gz: !binary |-
6
- N2ViNDY2ZTE0YTcyNDUwZDhlMzk2ZjYzMzc2NjlmYmM0YjRmMDY3NQ==
6
+ NjA2M2I0ZDljNjAwM2UwM2MwNWE1NjY5MDIyZmRkZjQ4NDM4OWZjMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmQzNjJhODlmMTg4NDJiZDc1YjEzOWJhODdiMGFmNjk0Y2U4ZTUzOGUyMzBm
10
- OTM0NDlkNWNiZjY5NzcxM2NkYjU1ZDM1MWYyMmYyYThmNzcyZDE1ZDhkMGMz
11
- MDI2MjJlYzZhOTFmNWZmOTk4YTkzMzJlYTkyNjQ0Y2I5YTA3NmM=
9
+ MTBlNzY4MmVhNDJjMWJiOTQyYjI3ZThjYmUzNjI2ZTBhOTczZTk3M2JlNjkz
10
+ MzYzYmUyMjk0ZjhhMmJjY2ZjZjA1MzMyYjczNWY4NmZmYzM1NjM3MjIxYTk0
11
+ MDU3NmM3ZDBmMmJiN2E0NWQ0OTI4YjFkZDNhNWNmMTRkODY1ZTc=
12
12
  data.tar.gz: !binary |-
13
- OTM1ZDIxZGEwZmViZjA0NmU3Nzc4M2YxZTFhZTg4MGQ5MzU3MGM4YzI0Y2Y0
14
- OTUzYzM1NzRkNzQ3YmFjZDM0ZGEwZDg2MmM1YjUzMWEyZjBkOGJjODZkNTUy
15
- ZWY1MjFiZDFjYWQyZTE4YjdkYmJkNjdkNjE4ZjE3ZjM4NWM0ZWQ=
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 create set any value on any method and it will automatically create the getter and setter.
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 wrap it in a RecursiveStruct
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 }
@@ -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] }
@@ -1,3 +1,3 @@
1
1
  class RecursiveStruct
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -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
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-03 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler