static-struct 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/static_struct/structure.rb +11 -4
- data/lib/static_struct/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f1a3241e46353cfd9040437c6922494aeb95f7
|
4
|
+
data.tar.gz: 37c5d3a05b4e8d94c61f324872787e32bda72889
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc6e741a80a217054eef97c7293275ed9bc26637fcef36f56a76fef5b57a4464bf8bac3de2f2c577b9fbdcc290755a4f5dc873fb50b705b2b0eb7566cfddfab0
|
7
|
+
data.tar.gz: c9890204f6e2268ce5ce2396be1b512939360a19b11e85bdbdf18d89f882f0d1a74b72e32abee48aa4ef226702a7660cc27d8be9e3576cda5edb3fbacc8fdae0
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Key features:
|
|
9
9
|
* Nesting hashes and respond to objects `to_hash` methods are allowed to do the convertation;
|
10
10
|
* There are no limitations of the nesting;
|
11
11
|
* It is not possible to call undefined methods;
|
12
|
-
* The defined dynamically structure is
|
12
|
+
* The defined dynamically structure is iterable (responds to `each`);
|
13
13
|
* The converted structure is *readonly*. It's not possible to rewrite defined values someway.
|
14
14
|
|
15
15
|
## Installation
|
@@ -47,6 +47,9 @@ struct.foo # => 'bar'
|
|
47
47
|
struct.foo_foo.foo # => 'bar'
|
48
48
|
struct.foo_fake # => NoMethodError: undefined method `foo_fake'
|
49
49
|
struct.foo = 'new bar' # => NoMethodError: undefined method `foo='
|
50
|
+
struct.enum_for(:each).map do |key, val|
|
51
|
+
[key, val]
|
52
|
+
end # => [["foo", "bar"], ["foo_foo", #<Enumerator: #<StaticStruct::Structure foo = bar>:each>]]
|
50
53
|
```
|
51
54
|
|
52
55
|
## Development
|
@@ -2,8 +2,6 @@ require 'set'
|
|
2
2
|
|
3
3
|
module StaticStruct
|
4
4
|
class Structure
|
5
|
-
include Enumerable
|
6
|
-
|
7
5
|
attr_reader :static_methods
|
8
6
|
|
9
7
|
def initialize(hash)
|
@@ -19,13 +17,22 @@ module StaticStruct
|
|
19
17
|
"#<#{joined_line}>"
|
20
18
|
end
|
21
19
|
|
20
|
+
def inspect
|
21
|
+
to_s
|
22
|
+
end
|
23
|
+
|
22
24
|
def ==(other)
|
23
25
|
current_state == other.current_state
|
24
26
|
end
|
25
27
|
|
26
28
|
def each
|
27
29
|
static_methods.each do |m|
|
28
|
-
|
30
|
+
method_result = public_send(m)
|
31
|
+
if method_result.is_a?(self.class)
|
32
|
+
yield m, method_result.enum_for(:each)
|
33
|
+
else
|
34
|
+
yield m, public_send(m)
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
@@ -33,7 +40,7 @@ module StaticStruct
|
|
33
40
|
|
34
41
|
def current_state
|
35
42
|
static_methods.map do |method|
|
36
|
-
"#{method}
|
43
|
+
"#{method}=#{public_send(method)}"
|
37
44
|
end.join(' ')
|
38
45
|
end
|
39
46
|
|