rstructural 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rstructural/either.rb +6 -2
- data/lib/rstructural/struct.rb +5 -1
- data/rstructural.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b715e16b32cd82a10871b0c6348c36e579d096130452409f58a0f5fdbf5326
|
4
|
+
data.tar.gz: e1649f6c0b33922125ab134ed4da189748e3a09c71968d04fe5f2f4027273357
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e23fdf733e52dcbd316b4bc96afa60689b3ccd63cd1c9de99103b2adf7557710c2d6ca92c954c9aaa8dbfcd18dac1bbbbda88ab39f1e8365051b658e944ed95
|
7
|
+
data.tar.gz: c1a3dbf70f81a1b654175b9154f8b6ac14c8b1f4c80b3f89eafc1cfebe6cc40b6cdb238eba8c80b06cecad8f5e78854f9bd9025396b93f049f432d4a718570cd
|
data/lib/rstructural/either.rb
CHANGED
@@ -15,9 +15,13 @@ module Rstructural::Either
|
|
15
15
|
Right.new(obj)
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.try(&block)
|
18
|
+
def self.try(catch_nil: false, &block)
|
19
19
|
result = block.call
|
20
|
-
|
20
|
+
if catch_nil && result.nil?
|
21
|
+
Left.new(nil)
|
22
|
+
else
|
23
|
+
Right.new(result)
|
24
|
+
end
|
21
25
|
rescue => e
|
22
26
|
Left.new(e)
|
23
27
|
end
|
data/lib/rstructural/struct.rb
CHANGED
@@ -30,6 +30,10 @@ module Rstructural
|
|
30
30
|
"#{class_name}"
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.to_s
|
34
|
+
"<#{class_name}>"
|
35
|
+
end
|
36
|
+
|
33
37
|
def [](key)
|
34
38
|
_key = ("@" + key.to_s).to_sym
|
35
39
|
self.instance_variable_get(_key)
|
@@ -44,7 +48,7 @@ module Rstructural
|
|
44
48
|
if #{attributes.empty?}
|
45
49
|
"#{class_name}"
|
46
50
|
else
|
47
|
-
__attrs = Array[#{attributes.map { |attr| "'#{attr}: ' + @#{attr}.to_s" }.join(', ')}].join(", ")
|
51
|
+
__attrs = Array[#{attributes.map { |attr| "'#{attr}: ' + (@#{attr}.nil? ? 'nil' : @#{attr}.to_s)" }.join(', ')}].join(", ")
|
48
52
|
"#{class_name}(" + __attrs + ")"
|
49
53
|
end
|
50
54
|
end
|
data/rstructural.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rstructural
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- petitviolet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|