deterministic 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/either.rb +12 -12
- data/lib/deterministic/either.rb +5 -0
- data/lib/deterministic/version.rb +1 -1
- data/spec/lib/deterministic/either/either_shared.rb +27 -0
- data/spec/lib/deterministic/either/failure_spec.rb +3 -9
- data/spec/lib/deterministic/either/success_spec.rb +3 -16
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b0f292bd43ef9a647f89e10a27d7ee6c03f9c86
|
4
|
+
data.tar.gz: 353997a1fa950788805f34a170b6fb83f4e84829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 943ebb00ce456140da6bf042681b53383fa19fa84ca529f7852d0f0671d089d203b64152a42dd897ec7a1f2a2fca9a646e4aff0bb945bf1fe07ee5963835d73a
|
7
|
+
data.tar.gz: 2f9e20201ac9c8d9fd19672eb7abe5f27a12d156dce4b7b49d6244a1a4363fef7e0344564f0b876a330bf4cd7064c9d40b9d79de940f310a156e30357bbea021
|
data/either.rb
CHANGED
@@ -6,39 +6,39 @@ class Either
|
|
6
6
|
@value = value
|
7
7
|
return self
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def self.success(value)
|
11
11
|
Success.new(value)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def self.failure(value)
|
15
15
|
Failure.new(value)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
class Abstract
|
19
19
|
def initialize(value)
|
20
20
|
@value = value
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
class Success < Abstract
|
25
25
|
def <<(value)
|
26
26
|
@value = value
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def or(*args)
|
30
30
|
self
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def success?
|
34
34
|
true
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def failure?
|
38
38
|
false
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
class Failure < Abstract
|
43
43
|
def <<(value)
|
44
44
|
@value = value
|
@@ -51,7 +51,7 @@ class Either
|
|
51
51
|
def success?
|
52
52
|
false
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def failure?
|
56
56
|
true
|
57
57
|
end
|
@@ -63,7 +63,7 @@ class Builder
|
|
63
63
|
def initialize(deps)
|
64
64
|
@settings_adapter = deps.fetch(:settings)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def build
|
68
68
|
Either.new do
|
69
69
|
on_failure do |result|
|
@@ -73,7 +73,7 @@ class Builder
|
|
73
73
|
chain { @settings = @settings_adapter.call(a, b) }
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
end
|
78
78
|
|
79
79
|
module SettingsAdapter
|
@@ -94,4 +94,4 @@ module SettingsAdapter
|
|
94
94
|
api_token: ENV['SETTINGS_TOKEN']
|
95
95
|
}
|
96
96
|
end
|
97
|
-
end
|
97
|
+
end
|
data/lib/deterministic/either.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
shared_examples 'Either' do
|
2
|
+
let(:either_name) { described_class.name.split("::")[-1]}
|
3
|
+
specify { expect(subject.value).to eq 1 }
|
4
|
+
specify { expect(either.new(subject)).to eq either.new(1) }
|
5
|
+
|
6
|
+
it "#map" do
|
7
|
+
expect(either.new(1).map { |e| e + 1 }).to eq either.new(2)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#bind" do
|
11
|
+
expect(either.new(1).bind { |v| either.new(v + 1)}).to eq either.new(2)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "#to_json" do
|
15
|
+
expect(either.new({a: 1}).to_json).to eq "{\"#{either_name}\":{\"a\":1}}"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "#to_s" do
|
19
|
+
expect(either.new(1).to_s).to eq "1"
|
20
|
+
expect(either.new({a: 1}).to_s).to eq "{:a=>1}"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "#inspect" do
|
24
|
+
expect(either.new(1).inspect).to eq "#{either_name}(1)"
|
25
|
+
expect(either.new(:a=>1).inspect).to eq "#{either_name}({:a=>1})"
|
26
|
+
end
|
27
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require_relative '../monad_axioms'
|
3
|
+
require_relative 'either_shared'
|
3
4
|
|
4
5
|
include Deterministic
|
5
6
|
|
@@ -12,7 +13,6 @@ describe Deterministic::Failure do
|
|
12
13
|
subject { described_class.new(1) }
|
13
14
|
|
14
15
|
specify { expect(subject).to be_an_instance_of described_class }
|
15
|
-
specify { expect(subject.value).to eq 1 }
|
16
16
|
specify { expect(subject).to be_failure }
|
17
17
|
specify { expect(subject).not_to be_success }
|
18
18
|
|
@@ -20,15 +20,9 @@ describe Deterministic::Failure do
|
|
20
20
|
specify { expect(subject).to eq(described_class.new(1)) }
|
21
21
|
specify { expect(subject << Success(2)).to eq(Failure(1)) }
|
22
22
|
specify { expect(subject << Failure(2)).to eq(Failure(1)) }
|
23
|
-
specify { expect(Failure(subject)).to eq Failure(1) }
|
24
23
|
specify { expect(subject.map { |v| v + 1} ).to eq Failure(2) }
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
it "#to_s" do
|
31
|
-
expect(Failure(1).to_s).to eq "1"
|
32
|
-
expect(Failure({a: 1}).to_s).to eq "{:a=>1}"
|
25
|
+
it_behaves_like 'Either' do
|
26
|
+
let(:either) { described_class }
|
33
27
|
end
|
34
28
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require_relative '../monad_axioms'
|
3
|
+
require_relative 'either_shared'
|
3
4
|
|
4
5
|
include Deterministic
|
5
6
|
|
@@ -12,7 +13,6 @@ describe Deterministic::Success do
|
|
12
13
|
subject { described_class.new(1) }
|
13
14
|
|
14
15
|
specify { expect(subject).to be_an_instance_of described_class }
|
15
|
-
specify { expect(subject.value).to eq 1 }
|
16
16
|
specify { expect(subject).to be_success }
|
17
17
|
specify { expect(subject).not_to be_failure }
|
18
18
|
|
@@ -20,22 +20,9 @@ describe Deterministic::Success do
|
|
20
20
|
specify { expect(subject).to eq(described_class.new(1)) }
|
21
21
|
specify { expect(subject << Success(2)).to eq(Success(2)) }
|
22
22
|
specify { expect(subject << Failure(2)).to eq(Failure(2)) }
|
23
|
-
specify { expect(Success(subject)).to eq Success(1) }
|
24
23
|
specify { expect(subject.map { |v| v + 1} ).to eq Success(2) }
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
subject.bind { |v| true ? Success(v + 1) : Failure(v + 2)}
|
29
|
-
).to eq Success(2)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "#to_json" do
|
33
|
-
expect(Success({a: 1}).to_json).to eq '{"Success":{"a":1}}'
|
34
|
-
expect([Success(1)].to_json).to eq '[{"Success":1}]'
|
35
|
-
end
|
36
|
-
|
37
|
-
it "#to_s" do
|
38
|
-
expect(Success(1).to_s).to eq "1"
|
39
|
-
expect(Success({a: 1}).to_s).to eq "{:a=>1}"
|
25
|
+
it_behaves_like 'Either' do
|
26
|
+
let(:either) { described_class }
|
40
27
|
end
|
41
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deterministic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Zolnierek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- spec/lib/deterministic/attempt_all_spec.rb
|
141
141
|
- spec/lib/deterministic/core_ext/either_spec.rb
|
142
142
|
- spec/lib/deterministic/core_ext/object/either_spec.rb
|
143
|
+
- spec/lib/deterministic/either/either_shared.rb
|
143
144
|
- spec/lib/deterministic/either/failure_spec.rb
|
144
145
|
- spec/lib/deterministic/either/match_spec.rb
|
145
146
|
- spec/lib/deterministic/either/success_spec.rb
|
@@ -178,6 +179,7 @@ test_files:
|
|
178
179
|
- spec/lib/deterministic/attempt_all_spec.rb
|
179
180
|
- spec/lib/deterministic/core_ext/either_spec.rb
|
180
181
|
- spec/lib/deterministic/core_ext/object/either_spec.rb
|
182
|
+
- spec/lib/deterministic/either/either_shared.rb
|
181
183
|
- spec/lib/deterministic/either/failure_spec.rb
|
182
184
|
- spec/lib/deterministic/either/match_spec.rb
|
183
185
|
- spec/lib/deterministic/either/success_spec.rb
|