process_chain 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc609b40693758b3ae7c341f8204f49d14a7335a
4
+ data.tar.gz: a57d992dd7747b0a10713a0218586e85d4f700d7
5
+ SHA512:
6
+ metadata.gz: 2e6f4f2d3dde7b83e9329dfc4885eca6d383b0c4bf11f0aa602230c1d285886cfaad9dbf2edd6ba31cf6b8606c8a546f1a5c1ce53ed5847f95aa1665583f0f08
7
+ data.tar.gz: 6c228cbb851a1e99c94968a7862d9a6d0400195a1a11063a077386a57667d24f59dd24d05256ae6fb169e245f8ce2a9132fd99133b7b4c773e8c33242bbddc7b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+
2
+ AllCops:
3
+ TargetRubyVersion: 2.5
4
+
5
+ Exclude:
6
+ - vendor/**/*
7
+ - bin/**/*
8
+
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - spec/**/*_spec.rb
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at maxim21214@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in process_chain.gemspec
8
+ gemspec
9
+
10
+ group :development, :test do
11
+ gem 'bundler'
12
+ gem 'rake'
13
+ gem 'rubocop', '0.51.0'
14
+ gem 'yard'
15
+ end
16
+
17
+ group :test do
18
+ gem 'coveralls', '~> 0.8.17', require: false
19
+ gem 'rspec', '~> 3.0'
20
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ process_chain (0.1.0)
5
+ hashie (~> 3.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ coveralls (0.8.22)
12
+ json (>= 1.8, < 3)
13
+ simplecov (~> 0.16.1)
14
+ term-ansicolor (~> 1.3)
15
+ thor (~> 0.19.4)
16
+ tins (~> 1.6)
17
+ diff-lcs (1.3)
18
+ docile (1.3.1)
19
+ hashie (3.5.6)
20
+ json (2.1.0)
21
+ parallel (1.12.1)
22
+ parser (2.5.1.0)
23
+ ast (~> 2.4.0)
24
+ powerpack (0.1.2)
25
+ rainbow (2.2.2)
26
+ rake
27
+ rake (12.3.1)
28
+ rspec (3.7.0)
29
+ rspec-core (~> 3.7.0)
30
+ rspec-expectations (~> 3.7.0)
31
+ rspec-mocks (~> 3.7.0)
32
+ rspec-core (3.7.1)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-expectations (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-mocks (3.7.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.7.0)
40
+ rspec-support (3.7.1)
41
+ rubocop (0.51.0)
42
+ parallel (~> 1.10)
43
+ parser (>= 2.3.3.1, < 3.0)
44
+ powerpack (~> 0.1)
45
+ rainbow (>= 2.2.2, < 3.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (~> 1.0, >= 1.0.1)
48
+ ruby-progressbar (1.9.0)
49
+ simplecov (0.16.1)
50
+ docile (~> 1.1)
51
+ json (>= 1.8, < 3)
52
+ simplecov-html (~> 0.10.0)
53
+ simplecov-html (0.10.2)
54
+ term-ansicolor (1.6.0)
55
+ tins (~> 1.0)
56
+ thor (0.19.4)
57
+ tins (1.16.3)
58
+ unicode-display_width (1.4.0)
59
+ yard (0.9.12)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ bundler
66
+ coveralls (~> 0.8.17)
67
+ process_chain!
68
+ rake
69
+ rspec (~> 3.0)
70
+ rubocop (= 0.51.0)
71
+ yard
72
+
73
+ BUNDLED WITH
74
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Max Konin
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,86 @@
1
+ # ProcessChain
2
+
3
+ ProcessChain gives you a simple way to using the Railsway oriented programming pattern. And allows you to write code in a more functional style.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'process_chain'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install process_chain
20
+
21
+ ## Usage
22
+
23
+
24
+ ```ruby
25
+ class UpdateUserProcess
26
+ include ProcessChain
27
+
28
+ def assignee_attributes(attrs)
29
+ if_success do
30
+ return_success user: results.user.assigne_attributes(attrs)
31
+ end
32
+ end
33
+
34
+ def validate_user
35
+ if_success do
36
+ if results.user.valid?
37
+ return_fail errors: results.user.errors, user: results.user
38
+ else
39
+ return_success
40
+ end
41
+ end
42
+ end
43
+
44
+ def save_user
45
+ user = results.user
46
+ if_success do
47
+ if user.save
48
+ return_success user: user
49
+ else
50
+ return_fail user: results.user
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ ## Controller
57
+ def create
58
+ process = UpdateUserProcess.new(input: user)
59
+ .assignee_attributes(permitted_params)
60
+ .validate_user
61
+ .save_user
62
+ if process.success?
63
+ render status: :ok, json: process.results.user
64
+ else
65
+ render status: :bad_request, json: process.results.errors
66
+ end
67
+ end
68
+ ```
69
+
70
+ ## Development
71
+
72
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
+
74
+ 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).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/process_chain. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
+
84
+ ## Code of Conduct
85
+
86
+ Everyone interacting in the ProcessChain project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/process_chain/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "process_chain"
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
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ProcessChain
4
+ # :nodoc:
5
+ VERSION = '0.1.0'
6
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'process_chain/version'
4
+
5
+ require 'hashie'
6
+
7
+ # Base module for process chains
8
+ module ProcessChain
9
+ # :nodoc:
10
+ def self.included(base)
11
+ base.send :include, InstanceMethods
12
+
13
+ base.instance_eval do
14
+ attr_reader :results
15
+ end
16
+ end
17
+
18
+ # :nodoc:
19
+ module InstanceMethods
20
+ # Constructor
21
+ # @param input [Hash] input data for process
22
+ # @param success [true false] result of latest process
23
+ # @raise [ArgumentError] when input is not a Hash
24
+ # @return a new instance of class
25
+ def initialize(input: {}, success: true)
26
+ raise ArgumentError, '"input" should be a Hash' unless input.is_a? Hash
27
+ @success = success
28
+ @results = Hashie::Mash.new input
29
+ end
30
+
31
+ # @return [true false]
32
+ def success?
33
+ @success
34
+ end
35
+
36
+ # Execute passed code block if chain is success
37
+ # @yield code block to be executed on success
38
+ def if_success
39
+ return self unless success?
40
+ yield if success?
41
+ end
42
+
43
+ # Execute passed code block if chain is not success
44
+ # @yield code block to be executed on fail
45
+ def if_fail
46
+ return self if success?
47
+ yield
48
+ end
49
+
50
+ # Returns a new success instace of chain
51
+ # @param results [Hash] a new input for next process
52
+ def return_success(results = nil)
53
+ self.class.new input: build_new_result(results)
54
+ end
55
+
56
+ # Returns a new fail instace of chain
57
+ # @param results [Hash] a new input for next process
58
+ def return_fail(results = nil)
59
+ self.class.new input: build_new_result(results), success: false
60
+ end
61
+
62
+ private
63
+
64
+ def build_new_result(input)
65
+ input || results.dup
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,31 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'process_chain/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'process_chain'
10
+ spec.version = ProcessChain::VERSION
11
+ spec.authors = ['Max Konin']
12
+ spec.email = ['maxim21214@gmail.com']
13
+
14
+ spec.summary = 'Simple railway programming implamentation for Ruby'
15
+ spec.description = 'Simple railway programming implementation for Ruby. To allow describe business logic in Elixir style'
16
+ spec.homepage = 'https://github.com/max-konin/process_chain'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+
30
+ spec.add_dependency 'hashie', '~> 3.5'
31
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: process_chain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Konin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ description: Simple railway programming implementation for Ruby. To allow describe
70
+ business logic in Elixir style
71
+ email:
72
+ - maxim21214@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/process_chain.rb
90
+ - lib/process_chain/version.rb
91
+ - process_chain.gemspec
92
+ homepage: https://github.com/max-konin/process_chain
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.14
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Simple railway programming implamentation for Ruby
116
+ test_files: []