structure 2.0.0.beta → 2.0.0.beta.2

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
  SHA256:
3
- metadata.gz: deb97f3f6e161a8adad686e3245878eddfada43c12be7cce3b567c8a53e5616a
4
- data.tar.gz: 7eaac7c7ff94778b2df81ebff8473a52cc17582d885713c031fe04ecf8cf3053
3
+ metadata.gz: 29a70d1a2fd15666410907a7868ae65e78ea18d6c6167e7b8142a4eaac35c4e4
4
+ data.tar.gz: b8cd311d8398866e76b5c776a9f97d2b0dc6c521aba11bbe0d2578993d95c72f
5
5
  SHA512:
6
- metadata.gz: a859a498b3c11a6687b190de2985a176a1aaf9a803ce45dca5e016a11731f315dfacac1054521671409cf44206228d81582214316b1135e17c819c8ed36f5af1
7
- data.tar.gz: d13ea6ab654295856d7086eaccfbf109b2bd6734761484eb8b2f3049cb17b4a1697e8afddc25eb2ef317118581c746b4203c05c74d947b405f4d53e4d68c6c1f
6
+ metadata.gz: 7dfe13a99479e042c55d76db3b5bdb1ab52ca601097f5a0db569328ddfc02f97422a50b123267004c6af7b74711132a4977640a3e846348523b6007b1a1e0052
7
+ data.tar.gz: 322b7d2757a6135f8fb95ca258d3f607911d4408bd52c3ca1b7f0b319c1bea6f679b565df4758146a2c3b6d3c17882b910b04f9d3e1358921d84f5f21d212d0c
@@ -3,16 +3,6 @@
3
3
  # A tiny library for lazy parsing data with memoized attributes
4
4
  module Structure
5
5
  class << self
6
- def serialize(value)
7
- if value.respond_to?(:attributes)
8
- value.attributes
9
- elsif value.is_a?(::Array)
10
- value.map { |element| serialize(element) }
11
- else
12
- value
13
- end
14
- end
15
-
16
6
  private
17
7
 
18
8
  def included(base)
@@ -24,25 +14,28 @@ module Structure
24
14
  self.class.attribute_names
25
15
  end
26
16
 
27
- def attributes
28
- attribute_names.each_with_object({}) do |key, hash|
29
- hash[key] = ::Structure.serialize(send(key))
30
- end
17
+ def to_a
18
+ attribute_names.map { |key| [key, send(key)] }
31
19
  end
32
20
 
33
21
  def to_h
34
- attributes
22
+ Hash[to_a]
35
23
  end
36
24
 
37
- def to_s
38
- data = attribute_names.map { |key| "#{key}=#{send(key)}" }.join(', ')
39
- "#<#{[self.class.name, data].compact.join(' ')}>"
40
- end
25
+ alias attributes to_h
41
26
 
42
27
  def inspect
43
- to_s
28
+ detail = if self.class.method_defined?(:to_s, false)
29
+ to_s
30
+ else
31
+ to_a.map { |key, val| "#{key}=#{val.inspect}" }.join(', ')
32
+ end
33
+
34
+ "#<#{self.class.name || '?'} #{detail}>"
44
35
  end
45
36
 
37
+ alias to_s inspect
38
+
46
39
  def ==(other)
47
40
  attributes == other.attributes
48
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Structure
4
- VERSION = '2.0.0.beta'
4
+ VERSION = '2.0.0.beta.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structure
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta
4
+ version: 2.0.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari