teckel 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +67 -0
- data/.github/workflows/pages.yml +50 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +12 -0
- data/.ruby-version +1 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +0 -0
- data/DEVELOPMENT.md +28 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +71 -0
- data/LICENSE +201 -0
- data/README.md +62 -6
- data/Rakefile +25 -1
- data/bin/console +1 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +18 -0
- data/lib/teckel/chain.rb +186 -0
- data/lib/teckel/config.rb +69 -0
- data/lib/teckel/operation/results.rb +71 -0
- data/lib/teckel/operation.rb +340 -0
- data/lib/teckel/result.rb +63 -0
- data/lib/teckel/version.rb +3 -1
- data/lib/teckel.rb +8 -1
- data/teckel.gemspec +9 -4
- metadata +72 -7
- data/.travis.yml +0 -7
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Teckel
|
4
|
+
# Wrapper for +output+ and +error+ return values of Operations
|
5
|
+
#
|
6
|
+
# @example asking for status
|
7
|
+
#
|
8
|
+
# Teckel::Result.new("some output", true).successful? #=> true
|
9
|
+
# Teckel::Result.new("some output", true).failure? #=> false
|
10
|
+
#
|
11
|
+
# Teckel::Result.new("some error", false).successful? #=> false
|
12
|
+
# Teckel::Result.new("some error", false).failure? #=> true
|
13
|
+
#
|
14
|
+
# @example Use +.value+ to get the wrapped value regardless of success state
|
15
|
+
#
|
16
|
+
# Teckel::Result.new("some output", true).value #=> "some output"
|
17
|
+
# Teckel::Result.new("some error", false).value #=> "some error"
|
18
|
+
#
|
19
|
+
# @example Use +.success+ to get the wrapped value of a successful result
|
20
|
+
#
|
21
|
+
# # Note: The +.failure+ method works just the same for successful results
|
22
|
+
# Teckel::Result.new("some output", true).success #=> "some output"
|
23
|
+
# Teckel::Result.new("some error", false).success #=> nil
|
24
|
+
# Teckel::Result.new("some error", false).success("other default") #=> "other default"
|
25
|
+
# Teckel::Result.new("some error", false).success { |value| "Failed: #{value}" } #=> "Failed: some error"
|
26
|
+
#
|
27
|
+
# @api public
|
28
|
+
class Result
|
29
|
+
# @param value [Mixed] the value/payload of the result.
|
30
|
+
# @param success [Bool] whether this is a successful result
|
31
|
+
def initialize(value, success)
|
32
|
+
@value = value
|
33
|
+
@success = success
|
34
|
+
end
|
35
|
+
|
36
|
+
# @!attribute [r] value
|
37
|
+
# @return [Mixed] the value/payload
|
38
|
+
attr_reader :value
|
39
|
+
|
40
|
+
def successful?
|
41
|
+
@success
|
42
|
+
end
|
43
|
+
|
44
|
+
def failure?
|
45
|
+
!@success
|
46
|
+
end
|
47
|
+
|
48
|
+
def failure(default = nil, &block)
|
49
|
+
return @value if !@success
|
50
|
+
return yield(@value) if block
|
51
|
+
|
52
|
+
default
|
53
|
+
end
|
54
|
+
|
55
|
+
def success(default = nil, &block)
|
56
|
+
return @value if @success
|
57
|
+
|
58
|
+
return yield(@value) if block
|
59
|
+
|
60
|
+
default
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/teckel/version.rb
CHANGED
data/lib/teckel.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "teckel/version"
|
2
4
|
|
3
5
|
module Teckel
|
4
6
|
class Error < StandardError; end
|
5
|
-
# Your code goes here...
|
6
7
|
end
|
8
|
+
|
9
|
+
require_relative "teckel/config"
|
10
|
+
require_relative "teckel/operation"
|
11
|
+
require_relative "teckel/result"
|
12
|
+
require_relative "teckel/operation/results"
|
13
|
+
require_relative "teckel/chain"
|
data/teckel.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require "teckel/version"
|
5
6
|
|
@@ -8,21 +9,25 @@ Gem::Specification.new do |spec|
|
|
8
9
|
spec.version = Teckel::VERSION
|
9
10
|
spec.authors = ["Robert Schulze"]
|
10
11
|
spec.email = ["robert@dotless.de"]
|
12
|
+
spec.licenses = ['Apache-2.0']
|
11
13
|
|
12
14
|
spec.summary = 'Operations with enforced in/out/err data structures'
|
13
15
|
spec.description = 'Wrap your business logic into a common interface with enforced input, output and error data structures'
|
14
|
-
spec.homepage = "https://github.com/dotless-de/
|
16
|
+
spec.homepage = "https://github.com/dotless-de/teckel"
|
15
17
|
|
16
18
|
# Specify which files should be added to the gem when it is released.
|
17
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files = Dir.chdir(File.expand_path(
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
22
|
end
|
21
23
|
spec.bindir = "exe"
|
22
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
25
|
spec.require_paths = ["lib"]
|
24
26
|
|
25
|
-
spec.add_development_dependency "bundler", "~> 2.
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "dry-struct", ">= 1.1.1", "< 2"
|
26
29
|
spec.add_development_dependency "rake", ">= 10.0"
|
27
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "yard"
|
32
|
+
spec.add_development_dependency "yard-doctest"
|
28
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teckel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Schulze
|
@@ -16,14 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-struct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.1
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.1.1
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: rake
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +72,34 @@ dependencies:
|
|
52
72
|
- - "~>"
|
53
73
|
- !ruby/object:Gem::Version
|
54
74
|
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: yard
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: yard-doctest
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
55
103
|
description: Wrap your business logic into a common interface with enforced input,
|
56
104
|
output and error data structures
|
57
105
|
email:
|
@@ -60,19 +108,36 @@ executables: []
|
|
60
108
|
extensions: []
|
61
109
|
extra_rdoc_files: []
|
62
110
|
files:
|
111
|
+
- ".github/workflows/ci.yml"
|
112
|
+
- ".github/workflows/pages.yml"
|
63
113
|
- ".gitignore"
|
64
114
|
- ".rspec"
|
65
|
-
- ".
|
115
|
+
- ".rubocop.yml"
|
116
|
+
- ".ruby-version"
|
117
|
+
- ".yardopts"
|
118
|
+
- CHANGELOG.md
|
119
|
+
- DEVELOPMENT.md
|
66
120
|
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE
|
67
123
|
- README.md
|
68
124
|
- Rakefile
|
69
125
|
- bin/console
|
126
|
+
- bin/rake
|
127
|
+
- bin/rspec
|
128
|
+
- bin/rubocop
|
70
129
|
- bin/setup
|
71
130
|
- lib/teckel.rb
|
131
|
+
- lib/teckel/chain.rb
|
132
|
+
- lib/teckel/config.rb
|
133
|
+
- lib/teckel/operation.rb
|
134
|
+
- lib/teckel/operation/results.rb
|
135
|
+
- lib/teckel/result.rb
|
72
136
|
- lib/teckel/version.rb
|
73
137
|
- teckel.gemspec
|
74
|
-
homepage: https://github.com/dotless-de/
|
75
|
-
licenses:
|
138
|
+
homepage: https://github.com/dotless-de/teckel
|
139
|
+
licenses:
|
140
|
+
- Apache-2.0
|
76
141
|
metadata: {}
|
77
142
|
post_install_message:
|
78
143
|
rdoc_options: []
|
@@ -89,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
154
|
- !ruby/object:Gem::Version
|
90
155
|
version: '0'
|
91
156
|
requirements: []
|
92
|
-
rubygems_version: 3.
|
157
|
+
rubygems_version: 3.0.3
|
93
158
|
signing_key:
|
94
159
|
specification_version: 4
|
95
160
|
summary: Operations with enforced in/out/err data structures
|