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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fd1749e7ef593ea94f057e94a777de38336ffd2
4
- data.tar.gz: 693813979b021137ca0f96e6bdec419d2e8872d4
3
+ metadata.gz: a9f1a3241e46353cfd9040437c6922494aeb95f7
4
+ data.tar.gz: 37c5d3a05b4e8d94c61f324872787e32bda72889
5
5
  SHA512:
6
- metadata.gz: 413f7d0cca6d36a551e82b59b464cb954f7e8c2877d0bfc78c0db22fb10194491685763f0307ad46f3da0cad00312ff5bb9f3cf70583dc7c635d153e9db149b4
7
- data.tar.gz: 22055a15e112a16bb5e2d904b93150965a047763b7fbd0993cf6048aec4fafdbd21d0105ae8ee0fad656fa8c6d139f3397e1406b6d106ac5bb449377ef9570dc
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 enumerable;
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
- yield m, public_send(m)
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} = #{public_send(method)}"
43
+ "#{method}=#{public_send(method)}"
37
44
  end.join(' ')
38
45
  end
39
46
 
@@ -1,3 +1,3 @@
1
1
  module StaticStruct
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mezuka LLC