ok_nok 0.0.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9710785601667b0220dd5d1d211af18f6006a228
4
- data.tar.gz: 8b31d1c24fc43e1b66f694fe10a7ac83dba18a8c
2
+ SHA256:
3
+ metadata.gz: 2d85d1c1ea684abde0dba07ad461742fd98c434ed2de2132589949921b7b788f
4
+ data.tar.gz: 229a500ba0cd3bc06d632fb3b1e7f676b10f020a33ab0809bbe595a8b617302f
5
5
  SHA512:
6
- metadata.gz: a112205b4b1b45ab0cf912e5d08da6df6f384cb5895ddae2ceff5d796c6de9de8a845eac3b2f55ee99d21dcff8c530f3af02817f8d707f3911daf0d1aa1573db
7
- data.tar.gz: 40f3f6b11423464712d9471233bf9a4a4c875117c128b7917f6723b286b1ce5ab4d06181591837858f6882335323db0dac1ce29c65cf3778618de547fd35e86c
6
+ metadata.gz: a7666aaee0f0542c6116f0e49d7f0f984497ee5ddfa24fb9ac7cca9f9292e8685ef8be4f6c114bcc357608bec049fed8e84f50447632a2f50c7521acc7306971
7
+ data.tar.gz: 718eac86750e033b83e3753926f1156f22bfe0782da971e55fde72aca3338cf91a0c1511e68883024ef0e978b9ed03f9e54c60a5e0aa37e3ecee434551c4fe3a
data/.gitignore CHANGED
@@ -1,37 +1,37 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /test/tmp/
9
- /test/version_tmp/
10
- /tmp/
11
-
12
- ## Specific to RubyMotion:
13
- .dat*
14
- .repl_history
15
- build/
16
-
17
- ## Documentation cache and generated files:
18
- /.yardoc/
19
- /_yardoc/
20
- /doc/
21
- /rdoc/
22
-
23
- ## Environment normalisation:
24
- /.bundle/
25
- /vendor/bundle
26
- /lib/bundler/man/
27
-
28
- # for a library or gem, you might want to ignore these files since the code is
29
- # intended to run in multiple environments; otherwise, check them in:
30
- # Gemfile.lock
31
- # .ruby-version
32
- # .ruby-gemset
33
-
34
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
- .rvmrc
36
-
37
- .project
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ .project
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ok_nok (0.0.1)
4
+ ok_nok (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -23,7 +23,11 @@ GEM
23
23
 
24
24
  PLATFORMS
25
25
  x86-mingw32
26
+ x86_64-darwin-21
26
27
 
27
28
  DEPENDENCIES
28
29
  ok_nok!
29
- rspec
30
+ rspec (~> 3.0, >= 3.0.0)
31
+
32
+ BUNDLED WITH
33
+ 2.4.8
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 patrick-gleeson
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 patrick-gleeson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,73 +1,72 @@
1
- # ok_nok
2
- A utility for adding a variant of functional-style Either return values to Ruby code.
3
-
4
- [![Codeship Status for patrick-gleeson/ok_nok](https://www.codeship.io/projects/e971b5a0-e9b3-0132-e2ca-4602e60b2e9f/status?branch=master)](https://www.codeship.io/projects/82985)
5
-
6
- ##Rationale
7
- Functional programming includes the concept of the Either, a return value that has a Left or a Right. Traditionally a populated Left value represents failure, and can contain information about the failure and a populated Right represents success.
8
- That's nicely generic, but it's also hard to read and unintuitive unless you're used to the syntax.
9
-
10
- It's very common in MVC apps in particular to want to return either a successful result or nothing - e.g. when retrieving a Model object by ID from a database.
11
- The Option type, which returns either a Some instance or a None object, is designed to handle this, but it lacks the any way of indicating what went wrong in a None situation.
12
-
13
- So what we're looking for is a neat way of either returning a value if an operation completed successfully, or returning an error explanation if it didn't. And we want it to be impossible to mistake the error explanation for a valid returned result.
14
-
15
- Either classes are too generic, as are Scala-style tuples. Option classes are too limited. Raising Exceptions is a bit heavy-handed. Presenting, then, ok_nok.
16
-
17
- ##Installation
18
- (Coming soon)
19
- As per any gem, add `gem 'ok_nok'` to your gemfile and `bundle` yourself, or just run `gem install ok_nok`
20
-
21
- ##Usage
22
- An ok_nok function always returns an instance of OkNok, whose status is set to either `ok` or `nok` (not ok). `ok` and `nok` methods monkey-patched into the Object class make this easy, e.g.:
23
-
24
- def multiple_foos(multiplier)
25
- if (intified = Integer(multiplier) rescue false)
26
- ok("foo" * intified)
27
- else
28
- nok("'#{multiplier}' can't be converted to an Integer so can't be used to multiply foo")
29
- end
30
- end
31
-
32
- At the most basic level you can then query the OkNok object about its status, like so:
33
-
34
- result = multiple_foos(gets)
35
- if result.ok?
36
- puts result.value
37
- else
38
- puts "Uh-Oh! #{result.value}"
39
- end
40
-
41
- But OkNoks also enable other, slightly more convenient control structures, e.g.:
42
-
43
- result = multiple_foos(gets).value_or_if_nok do |nok_value|
44
- # The code here only gets executed if multiple_foos is not ok
45
- end
46
-
47
- # result will be either the ok value, or the return value of the block
48
-
49
- Also you can do:
50
-
51
- multiple_foos(gets).ok {|ok_value|
52
- #This block gets called if multiple_foos is ok
53
- }.nok {|nok_value|
54
- #This block gets called if multiple_foos is not ok
55
- }
56
-
57
- You can wrap a block in an OkNok, if you specify what a nok result looks like:
58
-
59
- result = OkNok.nok_if(nil, "No 'e' was found") do
60
- gets.index("e")
61
- end
62
-
63
- Finally, you can wrap a block in an OkNok and have it return a nok only if an exception is raised
64
-
65
- result = OkNok.nok_if_exception("Uh-oh, my block raised an exception") do
66
- Integer(gets)
67
- end
68
-
69
- Note that in the above examples the nok value has been a user-friendly error message string. Of course, this could be a L10n key, a symbol, a Proc, or any sort of object that helps you deal with not-ok scenarios.
70
-
71
-
72
- ##Licence
73
- Licensed under the MIT licence.
1
+ # ok_nok
2
+ A utility for adding a variant of functional-style Either return values to Ruby code.
3
+
4
+ [![Codeship Status for patrick-gleeson/ok_nok](https://www.codeship.io/projects/e971b5a0-e9b3-0132-e2ca-4602e60b2e9f/status?branch=master)](https://www.codeship.io/projects/82985)
5
+
6
+ ##Rationale
7
+ Functional programming includes the concept of the Either, a return value that has a Left or a Right. Traditionally a populated Left value represents failure, and can contain information about the failure and a populated Right represents success.
8
+ That's nicely generic, but it's also hard to read and unintuitive unless you're used to the syntax.
9
+
10
+ It's very common in MVC apps in particular to want to return either a successful result or nothing - e.g. when retrieving a Model object by ID from a database.
11
+ The Option type, which returns either a Some instance or a None object, is designed to handle this, but it lacks the any way of indicating what went wrong in a None situation.
12
+
13
+ So what we're looking for is a neat way of either returning a value if an operation completed successfully, or returning an error explanation if it didn't. And we want it to be impossible to mistake the error explanation for a valid returned result.
14
+
15
+ Either classes are too generic, as are Scala-style tuples. Option classes are too limited. Raising Exceptions is a bit heavy-handed. Presenting, then, ok_nok.
16
+
17
+ ##Installation
18
+ As per any gem published on RubyGems, add `gem 'ok_nok'` to your gemfile and do a command line `bundle`, or just run `gem install ok_nok`.
19
+
20
+ ##Usage
21
+ An ok_nok function always returns an instance of OkNok, whose status is set to either `ok` or `nok` (not ok). `ok` and `nok` methods monkey-patched into the Object class make this easy, e.g.:
22
+
23
+ def multiple_foos(multiplier)
24
+ if (intified = Integer(multiplier) rescue false)
25
+ ok("foo" * intified)
26
+ else
27
+ nok("'#{multiplier}' can't be converted to an Integer so can't be used to multiply foo")
28
+ end
29
+ end
30
+
31
+ At the most basic level you can then query the OkNok object about its status, like so:
32
+
33
+ result = multiple_foos(gets)
34
+ if result.ok?
35
+ puts result.value
36
+ else
37
+ puts "Uh-Oh! #{result.value}"
38
+ end
39
+
40
+ But OkNoks also enable other, slightly more convenient control structures, e.g.:
41
+
42
+ result = multiple_foos(gets).value_or_if_nok do |nok_value|
43
+ # The code here only gets executed if multiple_foos is not ok
44
+ end
45
+
46
+ # result will be either the ok value, or the return value of the block
47
+
48
+ Also you can do:
49
+
50
+ multiple_foos(gets).ok {|ok_value|
51
+ #This block gets called if multiple_foos is ok
52
+ }.nok {|nok_value|
53
+ #This block gets called if multiple_foos is not ok
54
+ }
55
+
56
+ You can wrap a block in an OkNok, if you specify what a nok result looks like:
57
+
58
+ result = OkNok.nok_if(nil, "No 'e' was found") do
59
+ gets.index("e")
60
+ end
61
+
62
+ Finally, you can wrap a block in an OkNok and have it return a nok only if an exception is raised
63
+
64
+ result = OkNok.nok_if_exception("Uh-oh, my block raised an exception") do
65
+ Integer(gets)
66
+ end
67
+
68
+ Note that in the above examples the nok value has been a user-friendly error message string. Of course, this could be a L10n key, a symbol, a Proc, or any sort of object that helps you deal with not-ok scenarios.
69
+
70
+
71
+ ##Licence
72
+ Licensed under the MIT licence.
@@ -1,11 +1,11 @@
1
- module OkNok
2
- module ObjectExtensions
3
- def ok(value)
4
- OkNok::Returnable.new(OkNok::OK, value)
5
- end
6
-
7
- def nok(value)
8
- OkNok::Returnable.new(OkNok::NOK, value)
9
- end
10
- end
11
- end
1
+ module OkNok
2
+ module ObjectExtensions
3
+ def ok(value)
4
+ OkNok::Returnable.new(OkNok::OK, value)
5
+ end
6
+
7
+ def nok(value)
8
+ OkNok::Returnable.new(OkNok::NOK, value)
9
+ end
10
+ end
11
+ end
@@ -1,44 +1,44 @@
1
- module OkNok
2
- class Returnable
3
- attr_reader :status, :value
4
-
5
- def initialize(status, value)
6
- raise ArgumentError, "Status must be OkNok::OK or OkNok::NOK" unless [OkNok::OK, OkNok::NOK].include? status
7
- @status, @value = status, value
8
- end
9
-
10
- def ok?
11
- @status == OkNok::OK
12
- end
13
-
14
- def nok?
15
- @status == OkNok::NOK
16
- end
17
-
18
- def value_or_if_nok
19
- return value if ok?
20
- return nil unless block_given?
21
- yield value
22
- end
23
-
24
- def value_or_if_ok
25
- return value if nok?
26
- return nil unless block_given?
27
- yield value
28
- end
29
-
30
- def ok
31
- if ok?
32
- yield value if block_given?
33
- end
34
- return self
35
- end
36
-
37
- def nok
38
- if nok?
39
- yield value if block_given?
40
- end
41
- return self
42
- end
43
- end
44
- end
1
+ module OkNok
2
+ class Returnable
3
+ attr_reader :status, :value
4
+
5
+ def initialize(status, value)
6
+ raise ArgumentError, "Status must be OkNok::OK or OkNok::NOK" unless [OkNok::OK, OkNok::NOK].include? status
7
+ @status, @value = status, value
8
+ end
9
+
10
+ def ok?
11
+ @status == OkNok::OK
12
+ end
13
+
14
+ def nok?
15
+ @status == OkNok::NOK
16
+ end
17
+
18
+ def value_or_if_nok
19
+ return value if ok?
20
+ return nil unless block_given?
21
+ yield value
22
+ end
23
+
24
+ def value_or_if_ok
25
+ return value if nok?
26
+ return nil unless block_given?
27
+ yield value
28
+ end
29
+
30
+ def ok
31
+ if ok?
32
+ yield value if block_given?
33
+ end
34
+ return self
35
+ end
36
+
37
+ def nok
38
+ if nok?
39
+ yield value if block_given?
40
+ end
41
+ return self
42
+ end
43
+ end
44
+ end
@@ -1,4 +1,4 @@
1
- module OkNok
2
- OK = :ok
3
- NOK = :nok
4
- end
1
+ module OkNok
2
+ OK = :ok
3
+ NOK = :nok
4
+ end
@@ -1,3 +1,3 @@
1
1
  module OkNok
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/ok_nok.rb CHANGED
@@ -6,13 +6,13 @@ module OkNok
6
6
  def ok(value)
7
7
  OkNok::Returnable.new(OkNok::OK, value)
8
8
  end
9
-
9
+
10
10
  def nok(value)
11
11
  OkNok::Returnable.new(OkNok::NOK, value)
12
12
  end
13
-
13
+
14
14
  def self.nok_if(comparison_value, nok_value)
15
- raise ArgumentError, "You must provide a block" unless block_given?
15
+ raise ArgumentError, "You must provide a block." unless block_given?
16
16
  block_result = yield
17
17
  if block_result == comparison_value
18
18
  nok nok_value
@@ -20,9 +20,9 @@ module OkNok
20
20
  ok block_result
21
21
  end
22
22
  end
23
-
23
+
24
24
  def self.nok_if_exception(nok_value)
25
- raise ArgumentError, "You must provide a block" unless block_given?
25
+ raise ArgumentError, "You must provide a block." unless block_given?
26
26
  begin
27
27
  ok yield
28
28
  rescue StandardError
data/ok_nok.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "ok_nok"
7
7
  s.version = OkNok::VERSION
8
8
  s.authors = ["Patrick Gleeson"]
9
- s.email = ["hello@patrickgleeson.com"]
10
- s.homepage = "https://github.com/patrick-gleeson"
9
+ s.email = ["hello@tabletopgroupfinder.co.uk"]
10
+ s.homepage = "https://tabletopgroupfinder.co.uk"
11
11
  s.summary = %q{Success-failure utility}
12
12
  s.description = %q{A utility for adding a variant of functional-style Either return values to Ruby code.}
13
13
  s.license = "MIT"
data/spec/ok_nok_spec.rb CHANGED
@@ -1,147 +1,147 @@
1
- require 'spec_helper'
2
-
3
- include OkNok
4
-
5
- describe OkNok do
6
- let(:value_passed_in) { "SomeValue" }
7
- let(:provided_nok_value) { "Return me if nok" }
8
- let(:ok_block_return_value) { "other value" }
9
-
10
- describe '#ok' do
11
- subject { ok value_passed_in }
12
-
13
- specify do
14
- expect(subject).to be_an(OkNok)
15
- end
16
-
17
- it 'sets status to "ok"' do
18
- expect(subject.status).to be OkNok::OK
19
- end
20
-
21
- it 'keeps the value passed in' do
22
- expect(subject.value).to be value_passed_in
23
- end
24
- end
25
-
26
- describe '#nok' do
27
- subject { nok value_passed_in }
28
-
29
- specify do
30
- expect(subject).to be_an(OkNok)
31
- end
32
-
33
- it 'sets status to "nok"' do
34
- expect(subject.status).to be OkNok::NOK
35
- end
36
-
37
- it 'keeps the value passed in' do
38
- expect(subject.value).to be value_passed_in
39
- end
40
- end
41
-
42
- describe ".nok_if" do
43
- let(:comparison_value) {"If you get me, return a nok"}
44
-
45
- specify do
46
- expect{|block| OkNok.nok_if(comparison_value, provided_nok_value, &block)}.to yield_control
47
- end
48
-
49
- context "when no block is provided" do
50
- specify do
51
- expect{OkNok.nok_if(comparison_value, provided_nok_value)}.to raise_error(ArgumentError)
52
- end
53
- end
54
-
55
- context "when the block return value equals the comparison value" do
56
- subject do
57
- OkNok.nok_if comparison_value, provided_nok_value do
58
- comparison_value
59
- end
60
- end
61
-
62
- specify do
63
- expect(subject).to be_an(OkNok)
64
- end
65
-
66
- specify do
67
- expect(subject).to be_nok
68
- end
69
-
70
- it "assigns the provided value to the nok" do
71
- expect(subject.value).to eq provided_nok_value
72
- end
73
- end
74
-
75
- context "when the block return value doesn't equal the comparison value" do
76
- subject do
77
- OkNok.nok_if comparison_value, provided_nok_value do
78
- ok_block_return_value
79
- end
80
- end
81
-
82
- specify do
83
- expect(subject).to be_an(OkNok)
84
- end
85
-
86
- specify do
87
- expect(subject).to be_ok
88
- end
89
-
90
- it "assigns the block return value to the ok" do
91
- expect(subject.value).to eq ok_block_return_value
92
- end
93
- end
94
- end
95
-
96
- describe ".nok_if_exception" do
97
- specify do
98
- expect{|block| OkNok.nok_if_exception(provided_nok_value, &block)}.to yield_control
99
- end
100
-
101
- context "when no block is provided" do
102
- specify do
103
- expect{OkNok.nok_if_exception}.to raise_error(ArgumentError)
104
- end
105
- end
106
-
107
- context "when the block doesn't raise an exception" do
108
- subject do
109
- OkNok.nok_if_exception provided_nok_value do
110
- ok_block_return_value
111
- end
112
- end
113
-
114
- specify do
115
- expect(subject).to be_an(OkNok)
116
- end
117
-
118
- specify do
119
- expect(subject).to be_ok
120
- end
121
-
122
- it "assigns the block return value to the ok" do
123
- expect(subject.value).to eq ok_block_return_value
124
- end
125
- end
126
-
127
- context "when the block raises an exception" do
128
- subject do
129
- OkNok.nok_if_exception provided_nok_value do
130
- raise "This block has issues!"
131
- end
132
- end
133
- specify do
134
- expect(subject).to be_an(OkNok)
135
- end
136
-
137
- specify do
138
- expect(subject).to be_nok
139
- end
140
-
141
- it "assigns the provided return value to the nok" do
142
- expect(subject.value).to eq provided_nok_value
143
- end
144
- end
145
- end
146
- end
147
-
1
+ require 'spec_helper'
2
+
3
+ include OkNok
4
+
5
+ describe OkNok do
6
+ let(:value_passed_in) { "SomeValue" }
7
+ let(:provided_nok_value) { "Return me if nok" }
8
+ let(:ok_block_return_value) { "other value" }
9
+
10
+ describe '#ok' do
11
+ subject { ok value_passed_in }
12
+
13
+ specify do
14
+ expect(subject).to be_an(OkNok)
15
+ end
16
+
17
+ it 'sets status to "ok"' do
18
+ expect(subject.status).to be OkNok::OK
19
+ end
20
+
21
+ it 'keeps the value passed in' do
22
+ expect(subject.value).to be value_passed_in
23
+ end
24
+ end
25
+
26
+ describe '#nok' do
27
+ subject { nok value_passed_in }
28
+
29
+ specify do
30
+ expect(subject).to be_an(OkNok)
31
+ end
32
+
33
+ it 'sets status to "nok"' do
34
+ expect(subject.status).to be OkNok::NOK
35
+ end
36
+
37
+ it 'keeps the value passed in' do
38
+ expect(subject.value).to be value_passed_in
39
+ end
40
+ end
41
+
42
+ describe ".nok_if" do
43
+ let(:comparison_value) {"If you get me, return a nok"}
44
+
45
+ specify do
46
+ expect{|block| OkNok.nok_if(comparison_value, provided_nok_value, &block)}.to yield_control
47
+ end
48
+
49
+ context "when no block is provided" do
50
+ specify do
51
+ expect{OkNok.nok_if(comparison_value, provided_nok_value)}.to raise_error(ArgumentError)
52
+ end
53
+ end
54
+
55
+ context "when the block return value equals the comparison value" do
56
+ subject do
57
+ OkNok.nok_if comparison_value, provided_nok_value do
58
+ comparison_value
59
+ end
60
+ end
61
+
62
+ specify do
63
+ expect(subject).to be_an(OkNok)
64
+ end
65
+
66
+ specify do
67
+ expect(subject).to be_nok
68
+ end
69
+
70
+ it "assigns the provided value to the nok" do
71
+ expect(subject.value).to eq provided_nok_value
72
+ end
73
+ end
74
+
75
+ context "when the block return value doesn't equal the comparison value" do
76
+ subject do
77
+ OkNok.nok_if comparison_value, provided_nok_value do
78
+ ok_block_return_value
79
+ end
80
+ end
81
+
82
+ specify do
83
+ expect(subject).to be_an(OkNok)
84
+ end
85
+
86
+ specify do
87
+ expect(subject).to be_ok
88
+ end
89
+
90
+ it "assigns the block return value to the ok" do
91
+ expect(subject.value).to eq ok_block_return_value
92
+ end
93
+ end
94
+ end
95
+
96
+ describe ".nok_if_exception" do
97
+ specify do
98
+ expect{|block| OkNok.nok_if_exception(provided_nok_value, &block)}.to yield_control
99
+ end
100
+
101
+ context "when no block is provided" do
102
+ specify do
103
+ expect{OkNok.nok_if_exception}.to raise_error(ArgumentError)
104
+ end
105
+ end
106
+
107
+ context "when the block doesn't raise an exception" do
108
+ subject do
109
+ OkNok.nok_if_exception provided_nok_value do
110
+ ok_block_return_value
111
+ end
112
+ end
113
+
114
+ specify do
115
+ expect(subject).to be_an(OkNok)
116
+ end
117
+
118
+ specify do
119
+ expect(subject).to be_ok
120
+ end
121
+
122
+ it "assigns the block return value to the ok" do
123
+ expect(subject.value).to eq ok_block_return_value
124
+ end
125
+ end
126
+
127
+ context "when the block raises an exception" do
128
+ subject do
129
+ OkNok.nok_if_exception provided_nok_value do
130
+ raise "This block has issues!"
131
+ end
132
+ end
133
+ specify do
134
+ expect(subject).to be_an(OkNok)
135
+ end
136
+
137
+ specify do
138
+ expect(subject).to be_nok
139
+ end
140
+
141
+ it "assigns the provided return value to the nok" do
142
+ expect(subject.value).to eq provided_nok_value
143
+ end
144
+ end
145
+ end
146
+ end
147
+
@@ -1,178 +1,178 @@
1
- require 'spec_helper'
2
-
3
- describe OkNok::Returnable do
4
- let(:happy_value) { 'Hooray this worked' }
5
- let(:sad_value) { 'Oh no this failed' }
6
- let(:ok_object) {OkNok::Returnable.new(OkNok::OK, happy_value)}
7
- let(:nok_object){OkNok::Returnable.new(OkNok::NOK, sad_value) }
8
-
9
- context 'when initialized as ok' do
10
- describe '#value' do
11
- it 'contains the value passed in' do
12
- expect(ok_object.value).to eq happy_value
13
- end
14
- end
15
-
16
- describe '#status' do
17
- it 'is ok' do
18
- expect(ok_object.status).to eq OkNok::OK
19
- end
20
- end
21
-
22
- describe '#ok?' do
23
- it 'is true' do
24
- expect(ok_object.ok?).to eq true
25
- end
26
- end
27
-
28
- describe '#nok?' do
29
- it 'is false' do
30
- expect(ok_object.nok?).to eq false
31
- end
32
- end
33
-
34
- describe "#value_or_if_nok" do
35
- it "doesn't execute a provided block" do
36
- expect{|block| ok_object.value_or_if_nok(&block)}.not_to yield_control
37
- end
38
-
39
- it "returns its value" do
40
- expect(ok_object.value_or_if_nok {|nok_value| nil}).to eq ok_object.value
41
- end
42
- end
43
-
44
- describe "#value_or_if_ok" do
45
- it "executes a provided block" do
46
- expect{|block| ok_object.value_or_if_ok(&block)}.to yield_control
47
- end
48
-
49
- it "returns nil if no block provided" do
50
- expect(ok_object.value_or_if_ok).to be_nil
51
- end
52
-
53
- it "returns the result of the block if a block is provided" do
54
- expect(ok_object.value_or_if_ok {|nok_value| "Some result"}).to eq "Some result"
55
- end
56
-
57
- it "provides its value as an argument to the block" do
58
- ok_object.value_or_if_ok do |ok_value|
59
- expect(ok_value).to eq ok_object.value
60
- end
61
- end
62
- end
63
-
64
- describe "#ok" do
65
- it "executes a provided block" do
66
- expect{|block| ok_object.ok(&block)}.to yield_control
67
- end
68
-
69
- it "returns itself" do
70
- expect(ok_object.ok {|ok_value| nil}).to eq ok_object
71
- end
72
-
73
- it "provides its value as an argument to the block" do
74
- ok_object.ok do |ok_value|
75
- expect(ok_value).to eq ok_object.value
76
- end
77
- end
78
- end
79
-
80
- describe "#nok" do
81
- it "doesn't execute a provided block" do
82
- expect{|block| ok_object.nok(&block)}.not_to yield_control
83
- end
84
-
85
- it "returns itself" do
86
- expect(ok_object.nok {|nok_value| nil}).to eq ok_object
87
- end
88
- end
89
- end
90
-
91
- context 'when initialized as nok' do
92
- describe '#value' do
93
- it 'contains the value passed in' do
94
- expect(nok_object.value).to eq sad_value
95
- end
96
- end
97
-
98
- describe '#status' do
99
- it 'is nok' do
100
- expect(nok_object.status).to eq OkNok::NOK
101
- end
102
- end
103
-
104
- describe '#ok?' do
105
- it 'is false' do
106
- expect(nok_object.ok?).to eq false
107
- end
108
- end
109
-
110
- describe '#nok?' do
111
- it 'is true' do
112
- expect(nok_object.nok?).to eq true
113
- end
114
- end
115
-
116
- describe "#value_or_if_nok" do
117
- it "executes a provided block" do
118
- expect{|block| nok_object.value_or_if_nok(&block)}.to yield_control
119
- end
120
-
121
- it "returns nil if no block provided" do
122
- expect(nok_object.value_or_if_nok).to be_nil
123
- end
124
-
125
- it "returns the result of the block if a block is provided" do
126
- expect(nok_object.value_or_if_nok {|nok_value| "Some result"}).to eq "Some result"
127
- end
128
-
129
- it "provides the nok value as an argument to the block" do
130
- nok_object.value_or_if_nok do |nok_value|
131
- expect(nok_value).to eq nok_object.value
132
- end
133
- end
134
- end
135
-
136
- describe "#value_or_if_ok" do
137
- it "doesn't execute a provided block" do
138
- expect{|block| nok_object.value_or_if_ok(&block)}.not_to yield_control
139
- end
140
-
141
- it "returns its value" do
142
- expect(nok_object.value_or_if_ok {|ok_value| nil}).to eq nok_object.value
143
- end
144
- end
145
-
146
- describe "#ok" do
147
- it "doesn't execute a provided block" do
148
- expect{|block| nok_object.ok(&block)}.not_to yield_control
149
- end
150
-
151
- it "returns itself" do
152
- expect(nok_object.ok {|ok_value| nil}).to eq nok_object
153
- end
154
- end
155
-
156
- describe "#nok" do
157
- it "executes a provided block" do
158
- expect{|block| nok_object.nok(&block)}.to yield_control
159
- end
160
-
161
- it "returns itself" do
162
- expect(nok_object.nok {|nok_value| nil}).to eq nok_object
163
- end
164
-
165
- it "provides its value as an argument to the block" do
166
- nok_object.nok do |nok_value|
167
- expect(nok_value).to eq nok_object.value
168
- end
169
- end
170
- end
171
- end
172
-
173
- context 'when initialized with non ok/nok status' do
174
- it 'raises an ArgumentError' do
175
- expect{OkNok::Returnable.new("not a status", "some value")}.to raise_error(ArgumentError)
176
- end
177
- end
178
- end
1
+ require 'spec_helper'
2
+
3
+ describe OkNok::Returnable do
4
+ let(:happy_value) { 'Hooray this worked' }
5
+ let(:sad_value) { 'Oh no this failed' }
6
+ let(:ok_object) {OkNok::Returnable.new(OkNok::OK, happy_value)}
7
+ let(:nok_object){OkNok::Returnable.new(OkNok::NOK, sad_value) }
8
+
9
+ context 'when initialized as ok' do
10
+ describe '#value' do
11
+ it 'contains the value passed in' do
12
+ expect(ok_object.value).to eq happy_value
13
+ end
14
+ end
15
+
16
+ describe '#status' do
17
+ it 'is ok' do
18
+ expect(ok_object.status).to eq OkNok::OK
19
+ end
20
+ end
21
+
22
+ describe '#ok?' do
23
+ it 'is true' do
24
+ expect(ok_object.ok?).to eq true
25
+ end
26
+ end
27
+
28
+ describe '#nok?' do
29
+ it 'is false' do
30
+ expect(ok_object.nok?).to eq false
31
+ end
32
+ end
33
+
34
+ describe "#value_or_if_nok" do
35
+ it "doesn't execute a provided block" do
36
+ expect{|block| ok_object.value_or_if_nok(&block)}.not_to yield_control
37
+ end
38
+
39
+ it "returns its value" do
40
+ expect(ok_object.value_or_if_nok {|nok_value| nil}).to eq ok_object.value
41
+ end
42
+ end
43
+
44
+ describe "#value_or_if_ok" do
45
+ it "executes a provided block" do
46
+ expect{|block| ok_object.value_or_if_ok(&block)}.to yield_control
47
+ end
48
+
49
+ it "returns nil if no block provided" do
50
+ expect(ok_object.value_or_if_ok).to be_nil
51
+ end
52
+
53
+ it "returns the result of the block if a block is provided" do
54
+ expect(ok_object.value_or_if_ok {|nok_value| "Some result"}).to eq "Some result"
55
+ end
56
+
57
+ it "provides its value as an argument to the block" do
58
+ ok_object.value_or_if_ok do |ok_value|
59
+ expect(ok_value).to eq ok_object.value
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#ok" do
65
+ it "executes a provided block" do
66
+ expect{|block| ok_object.ok(&block)}.to yield_control
67
+ end
68
+
69
+ it "returns itself" do
70
+ expect(ok_object.ok {|ok_value| nil}).to eq ok_object
71
+ end
72
+
73
+ it "provides its value as an argument to the block" do
74
+ ok_object.ok do |ok_value|
75
+ expect(ok_value).to eq ok_object.value
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "#nok" do
81
+ it "doesn't execute a provided block" do
82
+ expect{|block| ok_object.nok(&block)}.not_to yield_control
83
+ end
84
+
85
+ it "returns itself" do
86
+ expect(ok_object.nok {|nok_value| nil}).to eq ok_object
87
+ end
88
+ end
89
+ end
90
+
91
+ context 'when initialized as nok' do
92
+ describe '#value' do
93
+ it 'contains the value passed in' do
94
+ expect(nok_object.value).to eq sad_value
95
+ end
96
+ end
97
+
98
+ describe '#status' do
99
+ it 'is nok' do
100
+ expect(nok_object.status).to eq OkNok::NOK
101
+ end
102
+ end
103
+
104
+ describe '#ok?' do
105
+ it 'is false' do
106
+ expect(nok_object.ok?).to eq false
107
+ end
108
+ end
109
+
110
+ describe '#nok?' do
111
+ it 'is true' do
112
+ expect(nok_object.nok?).to eq true
113
+ end
114
+ end
115
+
116
+ describe "#value_or_if_nok" do
117
+ it "executes a provided block" do
118
+ expect{|block| nok_object.value_or_if_nok(&block)}.to yield_control
119
+ end
120
+
121
+ it "returns nil if no block provided" do
122
+ expect(nok_object.value_or_if_nok).to be_nil
123
+ end
124
+
125
+ it "returns the result of the block if a block is provided" do
126
+ expect(nok_object.value_or_if_nok {|nok_value| "Some result"}).to eq "Some result"
127
+ end
128
+
129
+ it "provides the nok value as an argument to the block" do
130
+ nok_object.value_or_if_nok do |nok_value|
131
+ expect(nok_value).to eq nok_object.value
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "#value_or_if_ok" do
137
+ it "doesn't execute a provided block" do
138
+ expect{|block| nok_object.value_or_if_ok(&block)}.not_to yield_control
139
+ end
140
+
141
+ it "returns its value" do
142
+ expect(nok_object.value_or_if_ok {|ok_value| nil}).to eq nok_object.value
143
+ end
144
+ end
145
+
146
+ describe "#ok" do
147
+ it "doesn't execute a provided block" do
148
+ expect{|block| nok_object.ok(&block)}.not_to yield_control
149
+ end
150
+
151
+ it "returns itself" do
152
+ expect(nok_object.ok {|ok_value| nil}).to eq nok_object
153
+ end
154
+ end
155
+
156
+ describe "#nok" do
157
+ it "executes a provided block" do
158
+ expect{|block| nok_object.nok(&block)}.to yield_control
159
+ end
160
+
161
+ it "returns itself" do
162
+ expect(nok_object.nok {|nok_value| nil}).to eq nok_object
163
+ end
164
+
165
+ it "provides its value as an argument to the block" do
166
+ nok_object.nok do |nok_value|
167
+ expect(nok_value).to eq nok_object.value
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ context 'when initialized with non ok/nok status' do
174
+ it 'raises an ArgumentError' do
175
+ expect{OkNok::Returnable.new("not a status", "some value")}.to raise_error(ArgumentError)
176
+ end
177
+ end
178
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1 @@
1
- require 'ok_nok'
1
+ require 'ok_nok'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ok_nok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Gleeson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-31 00:00:00.000000000 Z
11
+ date: 2023-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -33,7 +33,7 @@ dependencies:
33
33
  description: A utility for adding a variant of functional-style Either return values
34
34
  to Ruby code.
35
35
  email:
36
- - hello@patrickgleeson.com
36
+ - hello@tabletopgroupfinder.co.uk
37
37
  executables: []
38
38
  extensions: []
39
39
  extra_rdoc_files: []
@@ -53,11 +53,11 @@ files:
53
53
  - spec/ok_nok_spec.rb
54
54
  - spec/returnable_spec.rb
55
55
  - spec/spec_helper.rb
56
- homepage: https://github.com/patrick-gleeson
56
+ homepage: https://tabletopgroupfinder.co.uk
57
57
  licenses:
58
58
  - MIT
59
59
  metadata: {}
60
- post_install_message:
60
+ post_install_message:
61
61
  rdoc_options: []
62
62
  require_paths:
63
63
  - lib
@@ -72,9 +72,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubyforge_project: ok_nok
76
- rubygems_version: 2.4.5
77
- signing_key:
75
+ rubygems_version: 3.4.8
76
+ signing_key:
78
77
  specification_version: 4
79
78
  summary: Success-failure utility
80
- test_files: []
79
+ test_files:
80
+ - spec/ok_nok_spec.rb
81
+ - spec/returnable_spec.rb
82
+ - spec/spec_helper.rb