tron 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -5
- data/lib/tron/version.rb +2 -2
- data/lib/tron.rb +0 -18
- metadata +31 -6
- data/lib/tron/failure.rb +0 -13
- data/lib/tron/resultable.rb +0 -65
- data/lib/tron/success.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3d033d6fa697cd4da7d443028e7ca891676266f8e41ecf00be057d52e84e0e0
|
4
|
+
data.tar.gz: 222f4a27b2acd1f887ee5deeb6e41b475f45c027c82663174129d7d83db6e5f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbb6fe573460da64aac5a59da8148fc766dfc73152cb8f887950fd4b99e90c7e2f9c0ebabed249d44f6e5b28dc912e48506866f29d0b44a65e84a7318f9339c8
|
7
|
+
data.tar.gz: 497c6f228706f96d9157a9600de35af4bd2e432177ed7c5e66c6c37e10f6dc74a874467a1b8ca235066619e36a3db8bea51c390bd5e540a2ab641e1dfe5f2617
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Tron is a minimalistic combination of a [monad](https://www.morozov.is/2018/09/08/monad-laws-in-ruby.html) and [value object](https://madeintandem.com/blog/creating-value-objects-in-ruby/), implemented in [a few lines](https://github.com/halo/tron/blob/master/lib/tron.rb) of code.
|
8
8
|
|
9
|
-
Return `Tron.success(:it_worked)` or `Tron.failure(:aww_too_bad)` from a method to explain why and how it succeded/failed. That returns an immutable Struct (value object) that responds to `result.success?` and `result.failure?`.
|
9
|
+
Return `Tron.success(:it_worked)` or `Tron.failure(:aww_too_bad)` from a method to explain why and how it succeded/failed. That returns an immutable Struct (value object) that responds to `result.success?` and `result.failure?`.
|
10
10
|
|
11
11
|
The reason is accessible in `result.success #=> :it_worked`. You can add more metadata as a second argument: `Tron.failure(:nopes, error_code: 404)` which you can access like a Struct: `result.error_code #=> 404`.
|
12
12
|
|
@@ -64,13 +64,13 @@ class User
|
|
64
64
|
def self.check_id_syntax(id)
|
65
65
|
return Tron.failure(:id_missing) unless id
|
66
66
|
return Tron.failure(:invalid_id, id: id) unless id.match /[a-f]{8}/
|
67
|
-
|
67
|
+
|
68
68
|
Tron.success :id_looks_good
|
69
69
|
end
|
70
70
|
|
71
71
|
def self.delete_user(id)
|
72
72
|
user = @users[id]
|
73
|
-
|
73
|
+
|
74
74
|
if @users.delete id
|
75
75
|
Tron.success :user_deleted, user: user
|
76
76
|
else
|
@@ -144,6 +144,10 @@ You cannot simply test for the `false` as expected return value because it could
|
|
144
144
|
|
145
145
|
While the code you're writing becomes slightly more verbose, that verbosity translates directly into documenation. You see immediately what each line is doing.
|
146
146
|
|
147
|
+
## Upgrading from 1.x.x to 2.0.0
|
148
|
+
|
149
|
+
* 1.2.0 and 2.0.0 are identical, except that all deprecations have been removed and don't work any more.
|
150
|
+
|
147
151
|
## Upgrading from 0.x.x to 1.x.x
|
148
152
|
|
149
153
|
* Don't use `include Tron`, it is not useful any more. There are no subclasses you might want to access.
|
@@ -157,7 +161,7 @@ Tron is a complete rewrite of its predecessor [operation](https://github.com/hal
|
|
157
161
|
|
158
162
|
## Requirements
|
159
163
|
|
160
|
-
* Ruby >= 2.
|
164
|
+
* Ruby >= 2.5.0
|
161
165
|
|
162
166
|
## Copyright
|
163
167
|
|
@@ -165,4 +169,4 @@ MIT 2015-2019 halo. See [MIT-LICENSE](http://github.com/halo/tron/blob/master/LI
|
|
165
169
|
|
166
170
|
## Caveats
|
167
171
|
|
168
|
-
* There are no setter methods in the returned Struct, so you cannot overwrite the metadata. The values are also frozen, so you don't accidentally modify the attributes in-place. However, they are not deep-frozen, so an object may still be modified if you're ignorant.
|
172
|
+
* There are no setter methods in the returned Struct, so you cannot overwrite the metadata. The values are also frozen, so you don't accidentally modify the attributes in-place. However, they are not deep-frozen, so an object may still be modified if you're ignorant.
|
data/lib/tron/version.rb
CHANGED
data/lib/tron.rb
CHANGED
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'tron/version'
|
4
4
|
|
5
|
-
require 'tron/resultable' # Legacy
|
6
|
-
require 'tron/success' # Legacy
|
7
|
-
require 'tron/failure' # Legacy
|
8
|
-
|
9
5
|
module Tron
|
10
6
|
def self.success(code, attributes = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
11
7
|
code.respond_to?(:to_sym) ||
|
@@ -33,13 +29,6 @@ module Tron
|
|
33
29
|
nil
|
34
30
|
end
|
35
31
|
|
36
|
-
def code
|
37
|
-
warn 'DEPRECATION WARNING: Calling `#code` on a Tron object is deprecated and will be removed in Tron 2.0.0. ' \
|
38
|
-
"Please use `#success` instead. Called from `#{caller.first}`"
|
39
|
-
|
40
|
-
success
|
41
|
-
end
|
42
|
-
|
43
32
|
def on_success(proc = nil, &block)
|
44
33
|
(proc || block).call self
|
45
34
|
end
|
@@ -76,13 +65,6 @@ module Tron
|
|
76
65
|
nil
|
77
66
|
end
|
78
67
|
|
79
|
-
def code
|
80
|
-
warn 'DEPRECATION WARNING: Calling `#code` on a Tron object is deprecated and will be removed in Tron 2.0.0. ' \
|
81
|
-
"Please use `#failure` instead. Called from `#{caller.first}`"
|
82
|
-
|
83
|
-
failure
|
84
|
-
end
|
85
|
-
|
86
68
|
def on_success(_ = nil)
|
87
69
|
self
|
88
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- halo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard-rspec
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: General-purpose method return objects that can be chained. Think minimalistic
|
70
98
|
value object monads. Heavily inspired by the `deterministic` gem, but much much
|
71
99
|
more light-weight.
|
@@ -76,9 +104,6 @@ extra_rdoc_files: []
|
|
76
104
|
files:
|
77
105
|
- README.md
|
78
106
|
- lib/tron.rb
|
79
|
-
- lib/tron/failure.rb
|
80
|
-
- lib/tron/resultable.rb
|
81
|
-
- lib/tron/success.rb
|
82
107
|
- lib/tron/version.rb
|
83
108
|
homepage: https://github.com/halo/tron
|
84
109
|
licenses:
|
@@ -92,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
117
|
requirements:
|
93
118
|
- - ">="
|
94
119
|
- !ruby/object:Gem::Version
|
95
|
-
version: 2.
|
120
|
+
version: 2.5.0
|
96
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
122
|
requirements:
|
98
123
|
- - ">="
|
data/lib/tron/failure.rb
DELETED
data/lib/tron/resultable.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module Tron
|
2
|
-
module Resultable
|
3
|
-
attr_reader :metadata
|
4
|
-
|
5
|
-
def self.included(receiver)
|
6
|
-
receiver.extend ::Tron::Resultable::ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
# Convenience wrapper
|
11
|
-
def call(code, metadata = nil)
|
12
|
-
new code: code, metadata: metadata
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(code: nil, metadata: nil)
|
17
|
-
@code = code
|
18
|
-
@metadata = metadata
|
19
|
-
warn 'DEPRECATION WARNING: As of Tron 1.0.0 calls to `Tron::Success.call` and `Tron::Failure.call` are deprecated. ' \
|
20
|
-
'They will be removed in Tron 2.0.0. Please migrate using `Tron.success` and `Tron.failure`. ' \
|
21
|
-
"See github.com/halo/tron Called in:: `#{caller[2]}`"
|
22
|
-
end
|
23
|
-
|
24
|
-
def success?
|
25
|
-
is_a? ::Tron::Success
|
26
|
-
end
|
27
|
-
|
28
|
-
def failure?
|
29
|
-
is_a? ::Tron::Failure
|
30
|
-
end
|
31
|
-
|
32
|
-
def code
|
33
|
-
return if @code.to_s == ''
|
34
|
-
|
35
|
-
@code.to_s.to_sym
|
36
|
-
end
|
37
|
-
|
38
|
-
# Convenience Wrapper
|
39
|
-
def object
|
40
|
-
metadata[:object] || metadata['object']
|
41
|
-
rescue StandardError
|
42
|
-
nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def meta
|
46
|
-
if defined? ::Hashie::Mash
|
47
|
-
metamash
|
48
|
-
else
|
49
|
-
metadata
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def metamash
|
56
|
-
if metadata.respond_to? :each_pair
|
57
|
-
::Hashie::Mash.new metadata
|
58
|
-
elsif metadata
|
59
|
-
metadata
|
60
|
-
else
|
61
|
-
::Hashie::Mash.new
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|