fluxo 0.1.0
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 +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +4 -0
- data/.tool-versions +1 -0
- data/.travis.yml +21 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +67 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bin/test +7 -0
- data/ci/Gemfile.activemodel-4 +6 -0
- data/ci/Gemfile.activemodel-4.lock +84 -0
- data/ci/Gemfile.activemodel-5 +6 -0
- data/ci/Gemfile.activemodel-5.lock +82 -0
- data/ci/Gemfile.activemodel-6 +6 -0
- data/ci/Gemfile.activemodel-6.lock +83 -0
- data/ci/Gemfile.activemodel-7 +6 -0
- data/ci/Gemfile.activemodel-7.lock +81 -0
- data/fluxo.gemspec +30 -0
- data/lib/fluxo/active_model_extension.rb +70 -0
- data/lib/fluxo/config.rb +33 -0
- data/lib/fluxo/errors.rb +19 -0
- data/lib/fluxo/operation/attributes.rb +69 -0
- data/lib/fluxo/operation/constructor.rb +31 -0
- data/lib/fluxo/operation.rb +154 -0
- data/lib/fluxo/result.rb +46 -0
- data/lib/fluxo/version.rb +5 -0
- data/lib/fluxo.rb +17 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c9233de7ffd75f41b5448b99093874d462f38eb53bd0230e87ce110618db4811
|
4
|
+
data.tar.gz: 8fc63126176a8f49904ad2c2276442cbe71799f61c35f7eacd64fcccd176142d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59f97254f8ef0ef915f8d3e7d3bc18dc37ef1873bfd845606a56250680bc7eac870504381908859d08693c8b7ac3619881ee8ab82c13ebdcfa236591cf41fda7
|
7
|
+
data.tar.gz: 0ab68181c7f41d299ca02272a216ea94bc2ff078f2c128f90cad99cd6ca88e362a398b127829ab9320a46aaafd4a576e2050d06d4c802bb117ade1461b56301f
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.2
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# dist: trusty
|
2
|
+
language: ruby
|
3
|
+
before_install:
|
4
|
+
- gem --version
|
5
|
+
- gem update bundler
|
6
|
+
- gem --version
|
7
|
+
- bash ci/setup.sh
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
fast_finish: true
|
11
|
+
include:
|
12
|
+
- rvm: 2.6
|
13
|
+
gemfile: Gemfile
|
14
|
+
- rvm: 2.6
|
15
|
+
gemfile: ci/Gemfile.activemodel-4
|
16
|
+
- rvm: 2.6
|
17
|
+
gemfile: ci/Gemfile.activemodel-5
|
18
|
+
- rvm: 2.6
|
19
|
+
gemfile: ci/Gemfile.activemodel-6
|
20
|
+
- rvm: 2.7.2
|
21
|
+
gemfile: ci/Gemfile.activemodel-7
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluxo (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
method_source (1.0.0)
|
13
|
+
parallel (1.21.0)
|
14
|
+
parser (3.0.3.2)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
pry (0.13.1)
|
17
|
+
coderay (~> 1.1)
|
18
|
+
method_source (~> 1.0)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (12.3.3)
|
21
|
+
regexp_parser (2.2.0)
|
22
|
+
rexml (3.2.5)
|
23
|
+
rspec (3.10.0)
|
24
|
+
rspec-core (~> 3.10.0)
|
25
|
+
rspec-expectations (~> 3.10.0)
|
26
|
+
rspec-mocks (~> 3.10.0)
|
27
|
+
rspec-core (3.10.1)
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-expectations (3.10.1)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-mocks (3.10.2)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.10.0)
|
35
|
+
rspec-support (3.10.2)
|
36
|
+
rubocop (1.23.0)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 3.0.0.0)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
regexp_parser (>= 1.8, < 3.0)
|
41
|
+
rexml
|
42
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
45
|
+
rubocop-ast (1.15.1)
|
46
|
+
parser (>= 3.0.1.1)
|
47
|
+
rubocop-performance (1.12.0)
|
48
|
+
rubocop (>= 1.7.0, < 2.0)
|
49
|
+
rubocop-ast (>= 0.4.0)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
standard (1.5.0)
|
52
|
+
rubocop (= 1.23.0)
|
53
|
+
rubocop-performance (= 1.12.0)
|
54
|
+
unicode-display_width (2.1.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
fluxo!
|
61
|
+
pry
|
62
|
+
rake (~> 12.0)
|
63
|
+
rspec
|
64
|
+
standard
|
65
|
+
|
66
|
+
BUNDLED WITH
|
67
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Marcos G. Zimmermann
|
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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Marcos G. Zimmermann
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Fluxo
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fluxo`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fluxo'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fluxo
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcosgz/fluxo.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluxo"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/test
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
fluxo (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.2.11.3)
|
10
|
+
activesupport (= 4.2.11.3)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activesupport (4.2.11.3)
|
13
|
+
i18n (~> 0.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
ast (2.4.2)
|
18
|
+
builder (3.2.4)
|
19
|
+
coderay (1.1.3)
|
20
|
+
concurrent-ruby (1.1.9)
|
21
|
+
diff-lcs (1.5.0)
|
22
|
+
i18n (0.9.5)
|
23
|
+
concurrent-ruby (~> 1.0)
|
24
|
+
method_source (1.0.0)
|
25
|
+
minitest (5.15.0)
|
26
|
+
parallel (1.21.0)
|
27
|
+
parser (3.1.0.0)
|
28
|
+
ast (~> 2.4.1)
|
29
|
+
pry (0.14.1)
|
30
|
+
coderay (~> 1.1)
|
31
|
+
method_source (~> 1.0)
|
32
|
+
rainbow (3.1.1)
|
33
|
+
rake (12.3.3)
|
34
|
+
regexp_parser (2.2.0)
|
35
|
+
rexml (3.2.5)
|
36
|
+
rspec (3.10.0)
|
37
|
+
rspec-core (~> 3.10.0)
|
38
|
+
rspec-expectations (~> 3.10.0)
|
39
|
+
rspec-mocks (~> 3.10.0)
|
40
|
+
rspec-core (3.10.1)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-expectations (3.10.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-mocks (3.10.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.10.0)
|
48
|
+
rspec-support (3.10.3)
|
49
|
+
rubocop (1.24.1)
|
50
|
+
parallel (~> 1.10)
|
51
|
+
parser (>= 3.0.0.0)
|
52
|
+
rainbow (>= 2.2.2, < 4.0)
|
53
|
+
regexp_parser (>= 1.8, < 3.0)
|
54
|
+
rexml
|
55
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
56
|
+
ruby-progressbar (~> 1.7)
|
57
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
58
|
+
rubocop-ast (1.15.1)
|
59
|
+
parser (>= 3.0.1.1)
|
60
|
+
rubocop-performance (1.13.1)
|
61
|
+
rubocop (>= 1.7.0, < 2.0)
|
62
|
+
rubocop-ast (>= 0.4.0)
|
63
|
+
ruby-progressbar (1.11.0)
|
64
|
+
standard (1.6.0)
|
65
|
+
rubocop (= 1.24.1)
|
66
|
+
rubocop-performance (= 1.13.1)
|
67
|
+
thread_safe (0.3.6)
|
68
|
+
tzinfo (1.2.9)
|
69
|
+
thread_safe (~> 0.1)
|
70
|
+
unicode-display_width (2.1.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
activemodel (~> 4.2)
|
77
|
+
fluxo!
|
78
|
+
pry
|
79
|
+
rake (~> 12.0)
|
80
|
+
rspec
|
81
|
+
standard
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
2.1.4
|
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
fluxo (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (5.2.6)
|
10
|
+
activesupport (= 5.2.6)
|
11
|
+
activesupport (5.2.6)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
ast (2.4.2)
|
17
|
+
coderay (1.1.3)
|
18
|
+
concurrent-ruby (1.1.9)
|
19
|
+
diff-lcs (1.5.0)
|
20
|
+
i18n (1.8.11)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
method_source (1.0.0)
|
23
|
+
minitest (5.15.0)
|
24
|
+
parallel (1.21.0)
|
25
|
+
parser (3.1.0.0)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
pry (0.14.1)
|
28
|
+
coderay (~> 1.1)
|
29
|
+
method_source (~> 1.0)
|
30
|
+
rainbow (3.1.1)
|
31
|
+
rake (12.3.3)
|
32
|
+
regexp_parser (2.2.0)
|
33
|
+
rexml (3.2.5)
|
34
|
+
rspec (3.10.0)
|
35
|
+
rspec-core (~> 3.10.0)
|
36
|
+
rspec-expectations (~> 3.10.0)
|
37
|
+
rspec-mocks (~> 3.10.0)
|
38
|
+
rspec-core (3.10.1)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-expectations (3.10.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-mocks (3.10.2)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-support (3.10.3)
|
47
|
+
rubocop (1.24.1)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 3.0.0.0)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
52
|
+
rexml
|
53
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.15.1)
|
57
|
+
parser (>= 3.0.1.1)
|
58
|
+
rubocop-performance (1.13.1)
|
59
|
+
rubocop (>= 1.7.0, < 2.0)
|
60
|
+
rubocop-ast (>= 0.4.0)
|
61
|
+
ruby-progressbar (1.11.0)
|
62
|
+
standard (1.6.0)
|
63
|
+
rubocop (= 1.24.1)
|
64
|
+
rubocop-performance (= 1.13.1)
|
65
|
+
thread_safe (0.3.6)
|
66
|
+
tzinfo (1.2.9)
|
67
|
+
thread_safe (~> 0.1)
|
68
|
+
unicode-display_width (2.1.0)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
ruby
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
activemodel (~> 5.2)
|
75
|
+
fluxo!
|
76
|
+
pry
|
77
|
+
rake (~> 12.0)
|
78
|
+
rspec
|
79
|
+
standard
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
2.1.4
|
@@ -0,0 +1,83 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
fluxo (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (6.1.4.4)
|
10
|
+
activesupport (= 6.1.4.4)
|
11
|
+
activesupport (6.1.4.4)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
|
+
ast (2.4.2)
|
18
|
+
coderay (1.1.3)
|
19
|
+
concurrent-ruby (1.1.9)
|
20
|
+
diff-lcs (1.5.0)
|
21
|
+
i18n (1.8.11)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
method_source (1.0.0)
|
24
|
+
minitest (5.15.0)
|
25
|
+
parallel (1.21.0)
|
26
|
+
parser (3.1.0.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
pry (0.14.1)
|
29
|
+
coderay (~> 1.1)
|
30
|
+
method_source (~> 1.0)
|
31
|
+
rainbow (3.1.1)
|
32
|
+
rake (12.3.3)
|
33
|
+
regexp_parser (2.2.0)
|
34
|
+
rexml (3.2.5)
|
35
|
+
rspec (3.10.0)
|
36
|
+
rspec-core (~> 3.10.0)
|
37
|
+
rspec-expectations (~> 3.10.0)
|
38
|
+
rspec-mocks (~> 3.10.0)
|
39
|
+
rspec-core (3.10.1)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-expectations (3.10.1)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-mocks (3.10.2)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-support (3.10.3)
|
48
|
+
rubocop (1.24.1)
|
49
|
+
parallel (~> 1.10)
|
50
|
+
parser (>= 3.0.0.0)
|
51
|
+
rainbow (>= 2.2.2, < 4.0)
|
52
|
+
regexp_parser (>= 1.8, < 3.0)
|
53
|
+
rexml
|
54
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
55
|
+
ruby-progressbar (~> 1.7)
|
56
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
57
|
+
rubocop-ast (1.15.1)
|
58
|
+
parser (>= 3.0.1.1)
|
59
|
+
rubocop-performance (1.13.1)
|
60
|
+
rubocop (>= 1.7.0, < 2.0)
|
61
|
+
rubocop-ast (>= 0.4.0)
|
62
|
+
ruby-progressbar (1.11.0)
|
63
|
+
standard (1.6.0)
|
64
|
+
rubocop (= 1.24.1)
|
65
|
+
rubocop-performance (= 1.13.1)
|
66
|
+
tzinfo (2.0.4)
|
67
|
+
concurrent-ruby (~> 1.0)
|
68
|
+
unicode-display_width (2.1.0)
|
69
|
+
zeitwerk (2.5.3)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
activemodel (~> 6.1)
|
76
|
+
fluxo!
|
77
|
+
pry
|
78
|
+
rake (~> 12.0)
|
79
|
+
rspec
|
80
|
+
standard
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
2.1.4
|
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
fluxo (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (7.0.1)
|
10
|
+
activesupport (= 7.0.1)
|
11
|
+
activesupport (7.0.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
ast (2.4.2)
|
17
|
+
coderay (1.1.3)
|
18
|
+
concurrent-ruby (1.1.9)
|
19
|
+
diff-lcs (1.5.0)
|
20
|
+
i18n (1.8.11)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
method_source (1.0.0)
|
23
|
+
minitest (5.15.0)
|
24
|
+
parallel (1.21.0)
|
25
|
+
parser (3.1.0.0)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
pry (0.14.1)
|
28
|
+
coderay (~> 1.1)
|
29
|
+
method_source (~> 1.0)
|
30
|
+
rainbow (3.1.1)
|
31
|
+
rake (12.3.3)
|
32
|
+
regexp_parser (2.2.0)
|
33
|
+
rexml (3.2.5)
|
34
|
+
rspec (3.10.0)
|
35
|
+
rspec-core (~> 3.10.0)
|
36
|
+
rspec-expectations (~> 3.10.0)
|
37
|
+
rspec-mocks (~> 3.10.0)
|
38
|
+
rspec-core (3.10.1)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-expectations (3.10.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-mocks (3.10.2)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-support (3.10.3)
|
47
|
+
rubocop (1.24.1)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 3.0.0.0)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
52
|
+
rexml
|
53
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.15.1)
|
57
|
+
parser (>= 3.0.1.1)
|
58
|
+
rubocop-performance (1.13.1)
|
59
|
+
rubocop (>= 1.7.0, < 2.0)
|
60
|
+
rubocop-ast (>= 0.4.0)
|
61
|
+
ruby-progressbar (1.11.0)
|
62
|
+
standard (1.6.0)
|
63
|
+
rubocop (= 1.24.1)
|
64
|
+
rubocop-performance (= 1.13.1)
|
65
|
+
tzinfo (2.0.4)
|
66
|
+
concurrent-ruby (~> 1.0)
|
67
|
+
unicode-display_width (2.1.0)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
activemodel (~> 7.0)
|
74
|
+
fluxo!
|
75
|
+
pry
|
76
|
+
rake (~> 12.0)
|
77
|
+
rspec
|
78
|
+
standard
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
2.1.4
|
data/fluxo.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "lib/fluxo/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "fluxo"
|
5
|
+
spec.version = Fluxo::VERSION
|
6
|
+
spec.authors = ["Marcos G. Zimmermann"]
|
7
|
+
spec.email = ["mgzmaster@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "Simple Ruby DSL to create operation service objects."
|
10
|
+
spec.description = "Simple Ruby DSL to create operation service objects"
|
11
|
+
spec.homepage = "https://github.com/marcosgz/fluxo"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/marcosgz/fluxo"
|
17
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
spec.add_development_dependency "standard"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
module Fluxo
|
3
|
+
module ActiveModelExtension
|
4
|
+
module ClassMethods
|
5
|
+
def validations(&block)
|
6
|
+
@validations_proxy ||= build_validations_proxy!
|
7
|
+
return unless block_given?
|
8
|
+
|
9
|
+
begin
|
10
|
+
@validations_proxy.class_eval(&block)
|
11
|
+
rescue => e
|
12
|
+
raise ValidationDefinitionError, <<~ERROR
|
13
|
+
Invalid validations for #{self.class.name}.
|
14
|
+
|
15
|
+
#{e.message}
|
16
|
+
ERROR
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def build_validations_proxy!
|
23
|
+
validator = Class.new do
|
24
|
+
include ActiveModel::Validations
|
25
|
+
|
26
|
+
def self.validate!(operation_instance, **attrs)
|
27
|
+
validator = new
|
28
|
+
|
29
|
+
attrs.each do |name, value|
|
30
|
+
validator.public_send(:"#{name}=", value)
|
31
|
+
end
|
32
|
+
|
33
|
+
if validator.valid?
|
34
|
+
operation_instance.Void()
|
35
|
+
else
|
36
|
+
operation_instance.Failure(:validation) { validator.errors }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def valid?
|
41
|
+
super
|
42
|
+
errors.empty?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
validator.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
47
|
+
attr_accessor #{attribute_names.map(&:inspect).join(", ")}
|
48
|
+
|
49
|
+
def self.model_name
|
50
|
+
::ActiveModel::Name.new(self, nil, %|#{name || "Anonymous"}|)
|
51
|
+
end
|
52
|
+
RUBY
|
53
|
+
|
54
|
+
validator
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module InstanceMethods
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.included(klass)
|
62
|
+
klass.extend(ClassMethods)
|
63
|
+
klass.send(:include, InstanceMethods)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Operation
|
68
|
+
include Fluxo::ActiveModelExtension
|
69
|
+
end
|
70
|
+
end
|
data/lib/fluxo/config.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fluxo
|
4
|
+
def self.config
|
5
|
+
@config ||= Config.new
|
6
|
+
yield(@config) if block_given?
|
7
|
+
@config
|
8
|
+
end
|
9
|
+
|
10
|
+
class Config
|
11
|
+
attr_reader :error_handlers
|
12
|
+
|
13
|
+
# When set to true, the result of a falsey operation will be wrapped in a Failure.
|
14
|
+
attr_accessor :wrap_falsey_result
|
15
|
+
|
16
|
+
# When set to true, the result of a truthy operation will be wrapped in a Success.
|
17
|
+
attr_accessor :wrap_truthy_result
|
18
|
+
|
19
|
+
# When set to true, the operation will not validate the transient_attributes defition during the flow step execution.
|
20
|
+
attr_accessor :sloppy_transient_attributes
|
21
|
+
|
22
|
+
# When set to true, the operation will not validate attributes definition before calling the operation.
|
23
|
+
attr_accessor :sloppy_attributes
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@error_handlers = []
|
27
|
+
@wrap_falsey_result = false
|
28
|
+
@wrap_truthy_result = false
|
29
|
+
@sloppy_transient_attributes = false
|
30
|
+
@sloppy_attributes = false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/fluxo/errors.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fluxo
|
2
|
+
class Error < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class InvalidResultError < Error
|
6
|
+
end
|
7
|
+
|
8
|
+
class AttributeError < Error
|
9
|
+
end
|
10
|
+
|
11
|
+
class NotDefinedAttributeError < AttributeError
|
12
|
+
end
|
13
|
+
|
14
|
+
class MissingAttributeError < AttributeError
|
15
|
+
end
|
16
|
+
|
17
|
+
class ValidationDefinitionError < Error
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fluxo
|
4
|
+
class Operation
|
5
|
+
module Attributes
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
attr_reader :validations_proxy
|
12
|
+
|
13
|
+
# When set to true, the operation will not validate the transient_attributes defition during the flow step execution.
|
14
|
+
attr_writer :sloppy_transient_attributes
|
15
|
+
|
16
|
+
# When set to true, the operation will not validate attributes definition before calling the operation.
|
17
|
+
attr_writer :sloppy_attributes
|
18
|
+
|
19
|
+
def sloppy_attributes?
|
20
|
+
return @sloppy_attributes if defined?(@sloppy_attributes)
|
21
|
+
|
22
|
+
Fluxo.config.sloppy_attributes
|
23
|
+
end
|
24
|
+
|
25
|
+
def sloppy_transient_attributes?
|
26
|
+
return @sloppy_transient_attributes if defined?(@sloppy_transient_attributes)
|
27
|
+
|
28
|
+
Fluxo.config.sloppy_transient_attributes
|
29
|
+
end
|
30
|
+
|
31
|
+
def validations
|
32
|
+
raise NotImplementedError, "ActiveModel is not defined to use validations."
|
33
|
+
end
|
34
|
+
|
35
|
+
def attribute_names
|
36
|
+
@attribute_names ||= []
|
37
|
+
end
|
38
|
+
|
39
|
+
def transient_attribute_names
|
40
|
+
@transient_attribute_names ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
def attributes(*names)
|
44
|
+
@attribute_names ||= []
|
45
|
+
names = names.map(&:to_sym) - @attribute_names
|
46
|
+
@attribute_names.push(*names)
|
47
|
+
end
|
48
|
+
|
49
|
+
def transient_attributes(*names)
|
50
|
+
@transient_attribute_names ||= []
|
51
|
+
names = names.map(&:to_sym) - @transient_attribute_names
|
52
|
+
@transient_attribute_names.push(*names)
|
53
|
+
end
|
54
|
+
|
55
|
+
def attribute?(key)
|
56
|
+
return false unless key
|
57
|
+
|
58
|
+
attribute_names.include?(key.to_sym)
|
59
|
+
end
|
60
|
+
|
61
|
+
def transient_attribute?(key)
|
62
|
+
return false unless key
|
63
|
+
|
64
|
+
transient_attribute_names.include?(key.to_sym)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fluxo
|
4
|
+
class Operation
|
5
|
+
module Constructor
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def inherited(subclass)
|
12
|
+
subclass.instance_variable_set(:@attribute_names, @attribute_names.dup)
|
13
|
+
end
|
14
|
+
|
15
|
+
def def_Operation(op_module)
|
16
|
+
tap do |klass|
|
17
|
+
op_module.define_singleton_method(:Operation) do |*attrs|
|
18
|
+
klass.Operation(*attrs)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def Operation(*attrs)
|
24
|
+
Class.new(self).tap do |klass|
|
25
|
+
klass.attributes(*attrs)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "operation/constructor"
|
4
|
+
require_relative "operation/attributes"
|
5
|
+
|
6
|
+
module Fluxo
|
7
|
+
class Operation
|
8
|
+
include Attributes
|
9
|
+
include Constructor
|
10
|
+
|
11
|
+
def_Operation(::Fluxo)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def flow(*methods)
|
15
|
+
define_method(:call!) { |**attrs| __execute_flow__(steps: methods, attributes: attrs) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(**attrs)
|
19
|
+
instance = new
|
20
|
+
|
21
|
+
begin
|
22
|
+
instance.__execute_flow__(steps: [:call!], attributes: attrs)
|
23
|
+
rescue InvalidResultError, AttributeError, ValidationDefinitionError => e
|
24
|
+
raise e
|
25
|
+
rescue => e
|
26
|
+
Fluxo::Result.new(type: :exception, value: e, operation: instance, ids: %i[error]).tap do |result|
|
27
|
+
Fluxo.config.error_handlers.each { |handler| handler.call(result) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def call!(**)
|
34
|
+
raise NotImplementedError, <<~ERROR
|
35
|
+
You must implement the #call! method in your operation.
|
36
|
+
For complexes operations, you can use the #flow method instead.
|
37
|
+
ERROR
|
38
|
+
end
|
39
|
+
|
40
|
+
# Calls step-method by step-method always passing the value to the next step
|
41
|
+
# If one of the methods is a failure stop the execution and return a result.
|
42
|
+
def __execute_flow__(steps: [], attributes: {})
|
43
|
+
transient_attributes = attributes.dup
|
44
|
+
__validate_attributes__(first_step: steps.first, attributes: transient_attributes)
|
45
|
+
|
46
|
+
result = nil
|
47
|
+
steps.unshift(:__validate__) if self.class.validations_proxy # add validate step before the first step
|
48
|
+
steps.each_with_index do |step, idx|
|
49
|
+
result = __wrap_result__(send(step, **transient_attributes))
|
50
|
+
break unless result.success?
|
51
|
+
|
52
|
+
if steps[idx + 1]
|
53
|
+
transient_attributes = __merge_result_attributes__(
|
54
|
+
new_attributes: result.value,
|
55
|
+
old_attributes: transient_attributes,
|
56
|
+
next_step: steps[idx + 1]
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param value_or_result_id [Any] The value for the result or the id when the result comes from block
|
64
|
+
def Success(value_or_result_id = nil)
|
65
|
+
attrs = {type: :ok, operation: self}
|
66
|
+
if block_given?
|
67
|
+
attrs[:ids] = value_or_result_id
|
68
|
+
attrs[:value] = yield
|
69
|
+
else
|
70
|
+
attrs[:value] = value_or_result_id
|
71
|
+
end
|
72
|
+
Fluxo::Result.new(**attrs)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param value_or_result_id [Any] The value for the result or the id when the result comes from block
|
76
|
+
def Failure(value_or_result_id = nil)
|
77
|
+
attrs = {type: :failure, operation: self}
|
78
|
+
if block_given?
|
79
|
+
attrs[:ids] = value_or_result_id
|
80
|
+
attrs[:value] = yield
|
81
|
+
else
|
82
|
+
attrs[:value] = value_or_result_id
|
83
|
+
end
|
84
|
+
Fluxo::Result.new(**attrs)
|
85
|
+
end
|
86
|
+
|
87
|
+
def Void
|
88
|
+
Success(:void) { nil }
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def __validate_attributes__(attributes:, first_step:)
|
94
|
+
if !self.class.sloppy_attributes? && (extra = attributes.keys - self.class.attribute_names).any?
|
95
|
+
raise NotDefinedAttributeError, <<~ERROR
|
96
|
+
The following attributes are not defined: #{extra.join(", ")}
|
97
|
+
|
98
|
+
You can use the #{self.class.name}.attributes method to specify list of allowed attributes.
|
99
|
+
Or you can disable strict attributes mode by setting the sloppy_attributes to true.
|
100
|
+
ERROR
|
101
|
+
end
|
102
|
+
|
103
|
+
method(first_step).parameters.select { |type, _| type == :keyreq }.each do |(_type, name)|
|
104
|
+
raise(MissingAttributeError, "Missing :#{name} attribute on #{self.class.name}#{first_step} step method.") unless attributes.key?(name)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def __merge_result_attributes__(new_attributes:, old_attributes:, next_step:)
|
109
|
+
return old_attributes unless new_attributes.is_a?(Hash)
|
110
|
+
|
111
|
+
attributes = old_attributes.merge(new_attributes)
|
112
|
+
allowed_attrs = self.class.attribute_names + self.class.transient_attribute_names
|
113
|
+
if !self.class.sloppy_transient_attributes? &&
|
114
|
+
(extra = attributes.keys - allowed_attrs).any?
|
115
|
+
raise NotDefinedAttributeError, <<~ERROR
|
116
|
+
The following transient attributes are not defined: #{extra.join(", ")}
|
117
|
+
|
118
|
+
You can use the #{self.class.name}.transient_attributes method to specify list of allowed attributes.
|
119
|
+
Or you can disable strict transient attributes mode by setting the sloppy_transient_attributes to true.
|
120
|
+
ERROR
|
121
|
+
end
|
122
|
+
|
123
|
+
method(next_step).parameters.select { |type, _| type == :keyreq }.each do |(_type, name)|
|
124
|
+
raise(MissingAttributeError, "Missing :#{name} transient attribute on #{self.class.name}##{next_step} step method.") unless attributes.key?(name)
|
125
|
+
end
|
126
|
+
|
127
|
+
attributes
|
128
|
+
end
|
129
|
+
|
130
|
+
def __validate__(**attributes)
|
131
|
+
self.class.validations_proxy.validate!(self, **attributes)
|
132
|
+
end
|
133
|
+
|
134
|
+
def __wrap_result__(result)
|
135
|
+
if result.is_a?(Fluxo::Result)
|
136
|
+
return result
|
137
|
+
elsif Fluxo.config.wrap_falsey_result && !result
|
138
|
+
return Failure(:falsey) { result }
|
139
|
+
elsif Fluxo.config.wrap_truthy_result && result
|
140
|
+
return Success(:truthy) { result }
|
141
|
+
end
|
142
|
+
|
143
|
+
raise InvalidResultError, <<~ERROR
|
144
|
+
The result of each step must be a Fluxo::Result.
|
145
|
+
You can use the #Success() and #Failure() methods to create a result.
|
146
|
+
|
147
|
+
This behavior can be changed by setting the Fluxo.config.wrap_falsey_result and Fluxo.config.wrap_truthy_result
|
148
|
+
configuration options.
|
149
|
+
|
150
|
+
The result of the operation is: #{result.inspect}
|
151
|
+
ERROR
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
data/lib/fluxo/result.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fluxo
|
4
|
+
class Result
|
5
|
+
attr_reader :operation, :type, :value, :ids
|
6
|
+
|
7
|
+
# @param options [Hash]
|
8
|
+
# @option options [Fluxo::Operation] :operation The operation instance that gererated this result
|
9
|
+
# @option options [symbol] :type The type of the result. Allowed types: :ok, :failure, :exception
|
10
|
+
# @option options [Any] :value The value of the result.
|
11
|
+
# @option options [Array<symbol>] :ids An identification to be used with the on_<success|failure|error> handlers
|
12
|
+
def initialize(operation:, type:, value:, ids: nil)
|
13
|
+
@operation = operation
|
14
|
+
@value = value
|
15
|
+
@type = type
|
16
|
+
@ids = Array(ids)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Boolean] true if the result is a success
|
20
|
+
def success?
|
21
|
+
type == :ok
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Boolean] true if the result is a failure
|
25
|
+
def failure?
|
26
|
+
type == :failure
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] true if the result is an exception
|
30
|
+
def error?
|
31
|
+
type == :exception
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_success(handler_id = nil)
|
35
|
+
tap { yield(self) if success? && (handler_id.nil? || ids.include?(handler_id)) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_failure(handler_id = nil)
|
39
|
+
tap { yield(self) if failure? && (handler_id.nil? || ids.include?(handler_id)) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def on_error(handler_id = nil)
|
43
|
+
tap { yield(self) if error? && (handler_id.nil? || ids.include?(handler_id)) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/fluxo.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "fluxo/version"
|
4
|
+
require_relative "fluxo/config"
|
5
|
+
require_relative "fluxo/errors"
|
6
|
+
require_relative "fluxo/operation"
|
7
|
+
require_relative "fluxo/result"
|
8
|
+
|
9
|
+
begin
|
10
|
+
require "active_model"
|
11
|
+
require_relative "fluxo/active_model_extension"
|
12
|
+
rescue LoadError
|
13
|
+
# do nothing
|
14
|
+
end
|
15
|
+
|
16
|
+
module Fluxo
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluxo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcos G. Zimmermann
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: standard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Simple Ruby DSL to create operation service objects
|
56
|
+
email:
|
57
|
+
- mgzmaster@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".tool-versions"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- bin/test
|
76
|
+
- ci/Gemfile.activemodel-4
|
77
|
+
- ci/Gemfile.activemodel-4.lock
|
78
|
+
- ci/Gemfile.activemodel-5
|
79
|
+
- ci/Gemfile.activemodel-5.lock
|
80
|
+
- ci/Gemfile.activemodel-6
|
81
|
+
- ci/Gemfile.activemodel-6.lock
|
82
|
+
- ci/Gemfile.activemodel-7
|
83
|
+
- ci/Gemfile.activemodel-7.lock
|
84
|
+
- fluxo.gemspec
|
85
|
+
- lib/fluxo.rb
|
86
|
+
- lib/fluxo/active_model_extension.rb
|
87
|
+
- lib/fluxo/config.rb
|
88
|
+
- lib/fluxo/errors.rb
|
89
|
+
- lib/fluxo/operation.rb
|
90
|
+
- lib/fluxo/operation/attributes.rb
|
91
|
+
- lib/fluxo/operation/constructor.rb
|
92
|
+
- lib/fluxo/result.rb
|
93
|
+
- lib/fluxo/version.rb
|
94
|
+
homepage: https://github.com/marcosgz/fluxo
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
homepage_uri: https://github.com/marcosgz/fluxo
|
99
|
+
source_code_uri: https://github.com/marcosgz/fluxo
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.3.0
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.1.4
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Simple Ruby DSL to create operation service objects.
|
119
|
+
test_files: []
|