chainit 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '01168d07cc80426d6f552a53c669e60bfaa496c2'
4
+ data.tar.gz: 6d88b99bc3f384eb8c9d03445edde207d4887c1a
5
+ SHA512:
6
+ metadata.gz: 5d2b4a9baf4f710d6972bf11a75181705f53ab303964e2d6c55fbb84823a1eb98642f8baf1f6faa1f880a605abb1034429d5d62ac4b9e75f63e6ed6e5e184b3e
7
+ data.tar.gz: 4912261e137808838b79759dea153ce84e49cf546254ff7e6edd8627d65fcbb7e4dcb029a0411adea805d07247bdf3fe9c79a612dbce518fb14f11b358d44835
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.4
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in chain_it.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 btolarz
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,61 @@
1
+ # ChainIt
2
+ [![CircleCI](https://circleci.com/gh/spark-solutions/ChainIt/tree/master.svg?style=svg&circle-token=3bb16aef0dbcbe7fd18500376a110bd6cedf668a)](https://circleci.com/gh/spark-solutions/ChainIt/tree/master)
3
+
4
+ ## Description
5
+ This provides the tool which is implementation of railway-oriented programming concept itself
6
+ (Read more on this <a href="https://fsharpforfunandprofit.com/rop">here</a>).
7
+
8
+ Ideally suited for executing task sequences that should be immediately interrupted when any subsequen task fails.
9
+
10
+ ## Usage
11
+ Everything comes down to chaining subsequent `#chain` method calls to a `ChainIt` object instance.
12
+
13
+ The gem supports design-by-contract programming concept - assuming every block related to `#chain` have to return both `#value` and `#failure?` aware object.We reccomend using Struct for that purpouse.
14
+
15
+ ```ruby
16
+ Result = Struct.new(:success, :value) do
17
+ def failure?
18
+ !success
19
+ end
20
+ end
21
+
22
+ ```
23
+ ### Examples
24
+
25
+ ```ruby
26
+ # Basic flow explanation
27
+ success = ->(value) { Result.new(true, value) }
28
+
29
+ ChainIt.new.
30
+ chain { success.call 2 }. #=> The subsequent chain will be triggered
31
+ chain { |num| success.call(num * 2) }. #=> We can pass the previous block evaluation as the block argument
32
+ chain { |num| success.call(num * 2) }.
33
+ result.
34
+ value #=> 8
35
+
36
+ # Working with #skip_next
37
+ ChainIt.new.
38
+ chain { success.call 2 }.
39
+ skip_next { |num| num == 2 }. #=> The next chain will be skipped conditionally since block returns true
40
+ chain { success.call 8 }.
41
+ chain { |num| success.call(num * 2) }. #=> The block argument is the last executed #chain value
42
+ result.
43
+ value #=> 4
44
+
45
+ # Dealing with a failure
46
+ failure = ->(value) { Result.new(false, value) }
47
+
48
+ ChainIt.new.
49
+ chain { success.call 2 }.
50
+ chain { failure.call 0 }. #=> All later #chain calls will be skipped
51
+ chain { success.call 4 }.
52
+ result.
53
+ value #=> 0
54
+ ```
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/spark-solutions/chain_it.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'chain_it'
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/chain_it.gemspec ADDED
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chain_it/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'chainit'
8
+ spec.version = ChainIt::VERSION
9
+ spec.authors = %w[btolarz nnande]
10
+ spec.email = ['btolarz@gmail.com']
11
+
12
+ spec.summary = 'A tool for executing successive tasks in a railway-oriented manner'
13
+ spec.description = "It can successfully replace conceptually similar libraries like Dry-transaction. It's all because of the simplicity its code offers."
14
+ spec.homepage = 'https://github.com/spark-solutions/chain_it'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.14'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,3 @@
1
+ class ChainIt
2
+ VERSION = '1.0.0'.freeze
3
+ end
data/lib/chain_it.rb ADDED
@@ -0,0 +1,33 @@
1
+ class ChainIt
2
+ def chain
3
+ if @skip_next
4
+ @skip_next = false
5
+ return self
6
+ end
7
+
8
+ return self if @skip
9
+ @skip_next = false
10
+ @result = yield @result&.value
11
+ @skip = true if @result.failure?
12
+ self
13
+ end
14
+
15
+ def skip_next
16
+ return self if @skip
17
+ @skip_next = yield @result&.value
18
+ self
19
+ end
20
+
21
+ def on_error
22
+ return self unless @skip
23
+ yield @result&.value
24
+ @skip = false
25
+ self
26
+ end
27
+
28
+ def result
29
+ @result
30
+ end
31
+ end
32
+
33
+ require 'chain_it/version'
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chainit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - btolarz
8
+ - nnande
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2018-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.14'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.14'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ description: It can successfully replace conceptually similar libraries like Dry-transaction.
57
+ It's all because of the simplicity its code offers.
58
+ email:
59
+ - btolarz@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".ruby-version"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - chain_it.gemspec
75
+ - lib/chain_it.rb
76
+ - lib/chain_it/version.rb
77
+ homepage: https://github.com/spark-solutions/chain_it
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.14
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A tool for executing successive tasks in a railway-oriented manner
101
+ test_files: []