static-struct 0.1.0 → 0.1.1

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: a1e9b770f3e58c7d6e5b7bb50776fa1adf37d5cd
4
- data.tar.gz: 14299c63a3f12251519fe94a9450b9505e541237
3
+ metadata.gz: 58615a4e4020074ad25736704b1735dcf4c2ff03
4
+ data.tar.gz: 637824c12247deda96a58c9422e7826369e1eb82
5
5
  SHA512:
6
- metadata.gz: 2edd1b2746cd61c726ab9e8dd71e030c27898773396cbdf603992c2b3a179e373ae653285346c8faf7a7fb20c0a4520576422334d17f486c440aeaa0f62d8df6
7
- data.tar.gz: 6d834805e5db6c48f46a08012ce6b483e685963770643aadf63fbbf0e1bfd29afb94451cee93bd1e039e12cd91d95990ec924480d72119f3926d3e2b04c7fd8d
6
+ metadata.gz: 556ad7e756ab9dc8c1ce2506cfc767bf23ba47eeb55cab17358627fa7c2a6115a7dd50f9c918b63714f1f2de354251d009ab0a5a84b55561171647a7b6d4321e
7
+ data.tar.gz: 8cd846995eb3ca8f3b75aa1b258bcbc9027b311096a94e1d47059fb561e26a5a48eb3b4600bde20edd84409b8f96014dd4db70c0511157c6c1414591992ca44a
@@ -1,9 +1,23 @@
1
1
  module StaticStruct
2
2
  class Structure
3
+ attr_reader :static_methods
4
+
3
5
  def initialize(hash)
6
+ @static_methods = []
4
7
  define_structure(self, hash)
5
8
  end
6
9
 
10
+ def inspect
11
+ methods = static_methods.sort.each_with_object({}) do |method, result|
12
+ result[method] = public_send(method)
13
+ end
14
+ "#<#{self.class} #{methods}>"
15
+ end
16
+
17
+ def ==(other)
18
+ inspect == other.inspect
19
+ end
20
+
7
21
  private
8
22
 
9
23
  def define_structure(parent, hash)
@@ -13,9 +27,22 @@ module StaticStruct
13
27
  end
14
28
 
15
29
  def safe_define_method(object, method, return_value)
16
- fail MethodAlreadyDefinedError, method if object.respond_to?(method)
30
+ if object.respond_to?(method)
31
+ fail MethodAlreadyDefinedError, "`#{method}' is already defined for #{object.inspect}"
32
+ end
17
33
 
34
+ object.static_methods.push(method.to_sym)
18
35
  case
36
+ when return_value.is_a?(Array)
37
+ object.define_singleton_method(method) do
38
+ return_value.map do |array_value|
39
+ if array_value.respond_to?(:to_hash)
40
+ Structure.new(array_value)
41
+ else
42
+ array_value
43
+ end
44
+ end
45
+ end
19
46
  when return_value.is_a?(Hash)
20
47
  object.define_singleton_method(method) { Structure.new(return_value) }
21
48
  when return_value.respond_to?(:to_hash)
@@ -1,3 +1,3 @@
1
1
  module StaticStruct
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mezuka LLC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-17 00:00:00.000000000 Z
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler