dry-monads 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dry-monads.gemspec +1 -0
- data/lib/dry/monads/maybe.rb +18 -0
- data/lib/dry/monads/version.rb +1 -1
- data/lib/json/add/dry/monads/maybe.rb +33 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8b7637e82c392e9033203131fc8a142dbb3c70d
|
4
|
+
data.tar.gz: accbe167e84adc328b782f52db264317396f0692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cba273461666107f402c9ef8ce31ad1c9924e6258b8cf4b16fc22439131084b31369fbce2c9c0c65339cb5d8bcf1e2c6b3076ca033e2e58bbe0bb8f3643d109
|
7
|
+
data.tar.gz: 601ca3bc9b87390cfe54e8698142cf8ffed94019bb0ce7f5be29c39bcbb23142a475ea977591fc2d8849ac2e405e0570d1b8ade01dc599171da3635264709202
|
data/dry-monads.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.bindir = 'exe'
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
|
+
spec.required_ruby_version = ">= 2.1.0"
|
28
29
|
spec.add_dependency 'dry-equalizer'
|
29
30
|
|
30
31
|
spec.add_development_dependency 'bundler'
|
data/lib/dry/monads/maybe.rb
CHANGED
@@ -92,6 +92,13 @@ module Dry
|
|
92
92
|
self
|
93
93
|
end
|
94
94
|
|
95
|
+
# Returns value. It exists to keep the interface identical to that of {Maybe::None}.
|
96
|
+
#
|
97
|
+
# @return [Object]
|
98
|
+
def value_or(_val)
|
99
|
+
value
|
100
|
+
end
|
101
|
+
|
95
102
|
# @return [String]
|
96
103
|
def to_s
|
97
104
|
"Some(#{value.inspect})"
|
@@ -144,6 +151,17 @@ module Dry
|
|
144
151
|
end
|
145
152
|
end
|
146
153
|
|
154
|
+
# Returns the passed value
|
155
|
+
#
|
156
|
+
# @returns [Object]
|
157
|
+
def value_or(val = nil)
|
158
|
+
if block_given?
|
159
|
+
yield
|
160
|
+
else
|
161
|
+
val
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
147
165
|
# @return [String]
|
148
166
|
def to_s
|
149
167
|
'None'
|
data/lib/dry/monads/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
require 'json' unless defined?(::JSON::JSON_LOADED) && ::JSON::JSON_LOADED
|
3
|
+
|
4
|
+
require 'dry/monads'
|
5
|
+
|
6
|
+
# Inspired by standard library implementation
|
7
|
+
# for Time serialization/deserialization see (json/lib/json/add/time.rb)
|
8
|
+
#
|
9
|
+
module Dry
|
10
|
+
module Monads
|
11
|
+
class Maybe
|
12
|
+
# Deserializes JSON string by using Dry::Monads::Maybe#lift method
|
13
|
+
def self.json_create(serialized)
|
14
|
+
lift(serialized.fetch('value'))
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
18
|
+
# object.
|
19
|
+
def as_json(*)
|
20
|
+
{
|
21
|
+
JSON.create_id => self.class.name,
|
22
|
+
value: value
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Stores class name (Dry::Monads::Maybe::Some or Dry::Monads::Maybe::None)
|
27
|
+
# with the monad value as JSON string
|
28
|
+
def to_json(*args)
|
29
|
+
as_json.to_json(*args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-monads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-equalizer
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/dry/monads/maybe.rb
|
93
93
|
- lib/dry/monads/try.rb
|
94
94
|
- lib/dry/monads/version.rb
|
95
|
+
- lib/json/add/dry/monads/maybe.rb
|
95
96
|
homepage: https://github.com/dry-rb/dry-monads
|
96
97
|
licenses:
|
97
98
|
- MIT
|
@@ -105,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
106
|
requirements:
|
106
107
|
- - ">="
|
107
108
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
109
|
+
version: 2.1.0
|
109
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
111
|
requirements:
|
111
112
|
- - ">="
|