tron 0.7.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tron.rb +76 -3
- data/lib/tron/failure.rb +0 -3
- data/lib/tron/resultable.rb +5 -2
- data/lib/tron/success.rb +0 -3
- data/lib/tron/version.rb +3 -3
- metadata +10 -10
- data/Rakefile +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 990e0bd04a0f3189d1483d9ebe010c740461aedc
|
4
|
+
data.tar.gz: e11e18fc405897c6d3fc36fd14440efd4b5a2bb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6651802dd7c1e274810caff0c0f0e924614da61c3861e66278264e24e91cc285c97d24c64c2d79528fcf7b4adfbbefe3eb0108559f1e7c31ec89be4e6fd9ff2f
|
7
|
+
data.tar.gz: 4aa73296745a4415dd108627176530b320408cd96e6f639b462aa5610fa8e8889ef42f2c6023097b2c5d7f0f9a7d5f44c8efa32236a777a52b379f7d775cfb85
|
data/lib/tron.rb
CHANGED
@@ -1,8 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tron/version'
|
2
4
|
|
3
|
-
require 'tron/resultable'
|
4
|
-
require 'tron/success'
|
5
|
-
require 'tron/failure'
|
5
|
+
require 'tron/resultable' # Legady
|
6
|
+
require 'tron/success' # Legacy
|
7
|
+
require 'tron/failure' # Legacy
|
6
8
|
|
7
9
|
module Tron
|
10
|
+
def self.success(code, attributes = {}) # rubocop:disable Metrics/MethodLength
|
11
|
+
code.respond_to?(:to_sym) ||
|
12
|
+
raise(ArgumentError, 'Tron.success must be called with a Symbol as first argument')
|
13
|
+
|
14
|
+
attributes.respond_to?(:keys)||
|
15
|
+
raise(ArgumentError, 'The attributes Hash for Tron.success must respond to #keys')
|
16
|
+
|
17
|
+
attributes.respond_to?(:values) ||
|
18
|
+
raise(ArgumentError, 'The attributes Hash for Tron.success must respond to #values')
|
19
|
+
|
20
|
+
Struct.new(:success, *attributes.keys) do
|
21
|
+
undef_method '[]='.to_sym
|
22
|
+
members.each { |member| undef_method "#{member}=".to_sym }
|
23
|
+
|
24
|
+
def success?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_success(proc = nil, &block)
|
37
|
+
(proc || block).call
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_failure(_ = nil)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
end.new code.to_sym, *attributes.values.map(&:freeze)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.failure(code, attributes = {}) # rubocop:disable Metrics/MethodLength
|
47
|
+
code.respond_to?(:to_sym) ||
|
48
|
+
raise(ArgumentError, 'Tron.failure must be called with a Symbol as first argument')
|
49
|
+
|
50
|
+
attributes.respond_to?(:keys)||
|
51
|
+
raise(ArgumentError, 'The attributes Hash for Tron.failure must respond to #keys')
|
52
|
+
|
53
|
+
attributes.respond_to?(:values) ||
|
54
|
+
raise(ArgumentError, 'The attributes Hash for Tron.failure must respond to #values')
|
55
|
+
|
56
|
+
Struct.new(:failure, *attributes.keys) do
|
57
|
+
undef_method '[]='.to_sym
|
58
|
+
members.each { |member| undef_method "#{member}=".to_sym }
|
59
|
+
|
60
|
+
def success?
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
def failure?
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
def success
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def on_success(_ = nil)
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def on_failure(proc = nil, &block)
|
77
|
+
(proc || block).call
|
78
|
+
end
|
79
|
+
end.new code.to_sym, *attributes.values.map(&:freeze)
|
80
|
+
end
|
8
81
|
end
|
data/lib/tron/failure.rb
CHANGED
data/lib/tron/resultable.rb
CHANGED
@@ -16,6 +16,9 @@ module Tron
|
|
16
16
|
def initialize(code: nil, metadata: nil)
|
17
17
|
@code = code
|
18
18
|
@metadata = metadata
|
19
|
+
warn 'DEPRECATED: As of Tron 1.0.0 calls to `Tron::Success` 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'
|
19
22
|
end
|
20
23
|
|
21
24
|
def success?
|
@@ -28,13 +31,14 @@ module Tron
|
|
28
31
|
|
29
32
|
def code
|
30
33
|
return if @code.to_s == ''
|
34
|
+
|
31
35
|
@code.to_s.to_sym
|
32
36
|
end
|
33
37
|
|
34
38
|
# Convenience Wrapper
|
35
39
|
def object
|
36
40
|
metadata[:object] || metadata['object']
|
37
|
-
rescue
|
41
|
+
rescue StandardError
|
38
42
|
nil
|
39
43
|
end
|
40
44
|
|
@@ -57,6 +61,5 @@ module Tron
|
|
57
61
|
::Hashie::Mash.new
|
58
62
|
end
|
59
63
|
end
|
60
|
-
|
61
64
|
end
|
62
65
|
end
|
data/lib/tron/success.rb
CHANGED
data/lib/tron/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- halo
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
11
11
|
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: guard-rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: hashie
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rb-fsevent
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -80,15 +80,15 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description: General-purpose method return objects that can be chained.
|
84
|
-
by the `deterministic` gem, but much much
|
83
|
+
description: General-purpose method return objects that can be chained. Think minimalistic
|
84
|
+
value object monads. Heavily inspired by the `deterministic` gem, but much much
|
85
|
+
more light-weight.
|
85
86
|
email:
|
86
87
|
executables: []
|
87
88
|
extensions: []
|
88
89
|
extra_rdoc_files: []
|
89
90
|
files:
|
90
91
|
- README.md
|
91
|
-
- Rakefile
|
92
92
|
- lib/tron.rb
|
93
93
|
- lib/tron/failure.rb
|
94
94
|
- lib/tron/resultable.rb
|
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 2.
|
109
|
+
version: 2.3.0
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
112
|
- - ">="
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.5.1
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: General-purpose method return objects that can be chained.
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|