structure 1.0.1 → 1.0.2
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 +4 -4
- data/lib/structure.rb +26 -22
- data/lib/structure/double.rb +4 -2
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823aad004c9d12efcd46068c366ea7b50bc1ba63
|
4
|
+
data.tar.gz: 7b6c6e8140da79339101ed1974a075fee8a04113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77b205fa19ebed7e7a2b85981f5536024632ee7544555b5e84c067704338519c3b57e5a72c47e590cb5c33a489146540ade0239af0f7bbf0e0386f3520f14479
|
7
|
+
data.tar.gz: 1fd8b8777da2398ccdd9558ba469ee4c35b937a017ed24b87f9f9b82769e7c6111005b9a29a6cc5af1ddec6ea0213ba878bf06eeb6b21cce64c7b44bfd5daf29
|
data/lib/structure.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Structure
|
1
2
|
module Structure
|
2
3
|
class << self
|
3
4
|
private
|
@@ -8,24 +9,25 @@ module Structure
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def attributes
|
11
|
-
attribute_names.reduce({})
|
12
|
+
attribute_names.reduce({}) do |hash, key|
|
12
13
|
value = send(key)
|
13
|
-
hash.update(
|
14
|
-
|
15
|
-
value.attributes
|
16
|
-
|
17
|
-
value.
|
18
|
-
|
19
|
-
element.attributes
|
20
|
-
|
21
|
-
|
14
|
+
hash.update(
|
15
|
+
key =>
|
16
|
+
if value.respond_to?(:attributes)
|
17
|
+
value.attributes
|
18
|
+
elsif value.is_a?(Array)
|
19
|
+
value.map do |element|
|
20
|
+
if element.respond_to?(:attributes)
|
21
|
+
element.attributes
|
22
|
+
else
|
23
|
+
element
|
24
|
+
end
|
22
25
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
26
|
+
else
|
27
|
+
value
|
28
|
+
end
|
27
29
|
)
|
28
|
-
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
33
|
def attribute_names
|
@@ -39,26 +41,28 @@ module Structure
|
|
39
41
|
|
40
42
|
def inspect
|
41
43
|
name = self.class.name || self.class.to_s.gsub(/[^\w:]/, "")
|
42
|
-
values =
|
43
|
-
|
44
|
+
values =
|
45
|
+
attribute_names
|
46
|
+
.map do |key|
|
44
47
|
value = send(key)
|
45
|
-
if
|
48
|
+
if value.is_a?(Array)
|
46
49
|
description = value.take(3).map(&:inspect).join(", ")
|
47
50
|
description += "..." if value.size > 3
|
48
51
|
"#{key}=[#{description}]"
|
49
52
|
else
|
50
53
|
"#{key}=#{value.inspect}"
|
51
54
|
end
|
52
|
-
|
55
|
+
end
|
53
56
|
.join(", ")
|
54
57
|
|
55
58
|
"#<#{name} #{values}>"
|
56
59
|
end
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
+
alias to_h attributes
|
62
|
+
alias eql? ==
|
63
|
+
alias to_s inspect
|
61
64
|
|
65
|
+
# ClassMethods
|
62
66
|
module ClassMethods
|
63
67
|
attr_reader :attribute_names
|
64
68
|
|
data/lib/structure/double.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Structure
|
2
|
+
# ClassMethods
|
2
3
|
module ClassMethods
|
3
4
|
def double
|
4
5
|
klass = Class.new(self)
|
@@ -13,9 +14,10 @@ module Structure
|
|
13
14
|
|
14
15
|
klass.module_eval do
|
15
16
|
def initialize(data = {})
|
16
|
-
data.each
|
17
|
+
data.each do |key, value|
|
18
|
+
value.freeze unless value.is_a?(Structure)
|
17
19
|
instance_variable_set(:"@#{key}", value)
|
18
|
-
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
attribute_names.each do |name|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: structure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hakan Ensari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email: me@hakanensari.com
|
43
57
|
executables: []
|
@@ -66,9 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
80
|
version: '0'
|
67
81
|
requirements: []
|
68
82
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.6.8
|
70
84
|
signing_key:
|
71
85
|
specification_version: 4
|
72
86
|
summary: Parse data into value objects
|
73
87
|
test_files: []
|
74
|
-
has_rdoc:
|