outcome 1.0.0 → 1.0.1
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/Rakefile +9 -0
- data/lib/outcome.rb +27 -0
- data/outcome.gemspec +23 -0
- data/spec/outcome_spec.rb +44 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: befe3c2c0b282b581de7fbb15fda29557e81da94
|
4
|
+
data.tar.gz: c92ada2f4a554925cd55f8107434ce44dfad7fba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a4cb88c4440215764a7c141964f62a0080de8fd8be1f964ab2d9f84ec77c5390cd47d30d6e95c4cc94048374a07e79543ed0a74ea58fe000d90231dc332fb84
|
7
|
+
data.tar.gz: a9040656a7eef6e595eb7b5e1c96be84361d1835971da2ce5b8eba0c4806cc4b879858943119e652ce09f6d9bc49e6ff73bee6d3f23c93b54db0d17cb3e0160e
|
data/Rakefile
ADDED
data/lib/outcome.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class Outcome
|
2
|
+
|
3
|
+
attr_reader :success, :result, :messages, :errors, :warnings
|
4
|
+
|
5
|
+
# Initializes an Outcome instance
|
6
|
+
# @param[Boolean] success indicates if process was successful.
|
7
|
+
# @param[Object] result the return value of the process. Anything you want to return
|
8
|
+
# @param[Array<String>, optional] messages messages as Array of strings, optional
|
9
|
+
# @param[Array<String>, optional] errors errors as Array of strings, optional
|
10
|
+
# @param[Array<String>, optional] warnings warnings as Array of strings, optional
|
11
|
+
def initialize(success, result, messages = [], errors = [], warnings = [])
|
12
|
+
@success, @result, @messages, @errors, @warnings = success, result, messages, errors, warnings
|
13
|
+
end
|
14
|
+
|
15
|
+
def success?
|
16
|
+
@success
|
17
|
+
end
|
18
|
+
|
19
|
+
def fail?
|
20
|
+
!@success
|
21
|
+
end
|
22
|
+
|
23
|
+
def messages_to_html
|
24
|
+
@messages.join('<br/>')
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/outcome.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'outcome'
|
7
|
+
spec.version = '1.0.1'
|
8
|
+
spec.authors = ['Jo Hund']
|
9
|
+
spec.email = ['jhund@clearcove.ca']
|
10
|
+
spec.summary = %q{Outcome provides a standardized container for the outcome of a Ruby process.}
|
11
|
+
spec.description = %q{Outcome provides a standardized container for the outcome of a Ruby process.}
|
12
|
+
spec.homepage = 'http://rails-recipes.clearcove.ca/pages/outcome.html'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency('rake')
|
21
|
+
spec.add_development_dependency('minitest')
|
22
|
+
spec.add_development_dependency('minitest-spec-expect')
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# dependencies
|
2
|
+
require 'rubygems'
|
3
|
+
require 'minitest'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
# Gem under test
|
7
|
+
require 'outcome'
|
8
|
+
|
9
|
+
describe Outcome do
|
10
|
+
|
11
|
+
describe '#initialize and accessors' do
|
12
|
+
let(:outcome) { Outcome.new(true, 'result', ['message'], ['error'], ['warning']) }
|
13
|
+
[
|
14
|
+
[:success, true],
|
15
|
+
[:result, 'result'],
|
16
|
+
[:messages, ['message']],
|
17
|
+
[:errors, ['error']],
|
18
|
+
[:warnings, ['warning']],
|
19
|
+
].each do |attr, expectation|
|
20
|
+
it "has the #{ attr } attribute" do
|
21
|
+
outcome.send(attr).must_equal(expectation)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#success' do
|
27
|
+
it 'handles true' do
|
28
|
+
Outcome.new(true, nil).success?.must_equal true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'handles false' do
|
32
|
+
Outcome.new(false, nil).success?.must_equal false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#messages_to_html' do
|
37
|
+
it 'returns messages as a string, each on a new line' do
|
38
|
+
Outcome.new(true, nil, %w[m1 m2 m3]).messages_to_html.must_equal(
|
39
|
+
'm1<br/>m2<br/>m3'
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: outcome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jo Hund
|
@@ -62,6 +62,10 @@ files:
|
|
62
62
|
- .gitignore
|
63
63
|
- LICENSE
|
64
64
|
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/outcome.rb
|
67
|
+
- outcome.gemspec
|
68
|
+
- spec/outcome_spec.rb
|
65
69
|
homepage: http://rails-recipes.clearcove.ca/pages/outcome.html
|
66
70
|
licenses:
|
67
71
|
- MIT
|
@@ -86,4 +90,5 @@ rubygems_version: 2.2.2
|
|
86
90
|
signing_key:
|
87
91
|
specification_version: 4
|
88
92
|
summary: Outcome provides a standardized container for the outcome of a Ruby process.
|
89
|
-
test_files:
|
93
|
+
test_files:
|
94
|
+
- spec/outcome_spec.rb
|