workflow-join 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09d63e2d8e1cc948a6cd156f826c75b8e3c0ac88
4
+ data.tar.gz: c6f9ef0cbfb2f147118ced9916ab77460f8bb127
5
+ SHA512:
6
+ metadata.gz: 462f516b6ea0a7a980b11338668d358a46890ab157c08c1b1f7b46969a8c030ca6e94e7917ceb044ec4aa76b1b204363c8490a44fc5d73b72679e8d20228a901
7
+ data.tar.gz: 80b1130fd8a22d0a1baa6bb8a3574201d95bffd96b428596b7c226fb9ca65482d0a0a1c4f90330caeb7f859255be4dc67ef6fe962528ccb777891d394ddcf80e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,60 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # Offense count: 6
4
+ # Cop supports --auto-correct.
5
+ # Configuration parameters: , SupportedStyles.
6
+ # SupportedStyles: only_raise, only_fail, semantic
7
+ Style/SignalException:
8
+ EnforcedStyle: semantic
9
+
10
+ Metrics/ClassLength:
11
+ Max: 200
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Max: 20
15
+
16
+ Metrics/LineLength:
17
+ Max: 180
18
+
19
+ Metrics/MethodLength:
20
+ Max: 50
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Max: 20
24
+
25
+ Metrics/AbcSize:
26
+ Max: 50
27
+
28
+ Style/EmptyCaseCondition:
29
+ Exclude:
30
+ - 'lib/**/*'
31
+ - 'spec/**/*'
32
+
33
+ Style/AsciiIdentifiers:
34
+ Exclude:
35
+ - 'lib/**/*'
36
+ - 'spec/**/*'
37
+
38
+ Style/AsciiComments:
39
+ Exclude:
40
+ - 'lib/**/*'
41
+ - 'spec/**/*'
42
+
43
+ Style/Documentation:
44
+ Exclude:
45
+ - 'lib/**/*'
46
+ - 'spec/**/*'
47
+
48
+ Style/RaiseArgs:
49
+ Exclude:
50
+ - 'lib/**/*'
51
+
52
+ Style/SpecialGlobalVars:
53
+ Exclude:
54
+ - 'lib/**/*'
55
+ - 'spec/**/*'
56
+
57
+ Style/MultilineBlockChain:
58
+ Exclude:
59
+ - 'lib/**/*'
60
+ - 'spec/**/*'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,67 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-09-15 16:00:14 +0200 using RuboCop version 0.42.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: AlignWith, SupportedStyles.
12
+ # SupportedStyles: either, start_of_block, start_of_line
13
+ Lint/BlockAlignment:
14
+ Exclude:
15
+ - 'lib/workflow/join.rb'
16
+
17
+ # Offense count: 1
18
+ Metrics/AbcSize:
19
+ Max: 49
20
+
21
+ # Offense count: 1
22
+ # Configuration parameters: CountComments.
23
+ Metrics/MethodLength:
24
+ Max: 46
25
+
26
+ # Offense count: 1
27
+ # Cop supports --auto-correct.
28
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
29
+ # SupportedStyles: call, braces
30
+ Style/LambdaCall:
31
+ Exclude:
32
+ - 'lib/workflow/join.rb'
33
+
34
+ # Offense count: 1
35
+ # Cop supports --auto-correct.
36
+ Style/MutableConstant:
37
+ Exclude:
38
+ - 'lib/workflow/join/version.rb'
39
+
40
+ # Offense count: 1
41
+ # Cop supports --auto-correct.
42
+ # Configuration parameters: PreferredDelimiters.
43
+ Style/PercentLiteralDelimiters:
44
+ Exclude:
45
+ - 'spec/workflow/join_spec.rb'
46
+
47
+ # Offense count: 1
48
+ # Cop supports --auto-correct.
49
+ Style/RescueModifier:
50
+ Exclude:
51
+ - 'lib/workflow/join.rb'
52
+
53
+ # Offense count: 4
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
56
+ # SupportedStyles: single_quotes, double_quotes
57
+ Style/StringLiterals:
58
+ Exclude:
59
+ - 'bin/console'
60
+ - 'lib/workflow/join/version.rb'
61
+
62
+ # Offense count: 2
63
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
64
+ # SupportedStyles: snake_case, camelCase
65
+ Style/VariableName:
66
+ Exclude:
67
+ - 'lib/workflow/join.rb'
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.8
4
+ - 2.2.2
5
+ - 2.3.1
6
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in workflow-join.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Aleksei Matiushkin
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,70 @@
1
+ # Workflow::Join
2
+
3
+ [![Build Status](https://travis-ci.org/am-kantox/workflow-join.svg?branch=master)](https://travis-ci.org/am-kantox/workflow-join)
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'workflow-join'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install workflow-join
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ class Master
26
+ include Workflow
27
+
28
+ attr_accessor :slave
29
+
30
+ def initialize(*)
31
+ @slave = Slave.new
32
+ end
33
+
34
+ workflow do
35
+ state :meeting do
36
+ event :go, transitions_to: :after_meeting
37
+ end
38
+ state :after_meeting
39
+
40
+ # before entering :after_meeting state, wait for @slave to enter :resolved state
41
+ guard :@slave, inner: :after_meeting, outer: :resolved
42
+ end
43
+ end
44
+
45
+ class Slave
46
+ include Workflow
47
+
48
+ workflow do
49
+ state :unresolved do
50
+ event :resolve, transitions_to: :resolved
51
+ end
52
+ state :resolved
53
+ end
54
+ end
55
+ ```
56
+
57
+ ## Development
58
+
59
+ 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.
60
+
61
+ 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).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/workflow-join. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
66
+
67
+
68
+ ## License
69
+
70
+ 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,24 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+
4
+ require 'bundler'
5
+ require 'bundler/setup'
6
+ require 'bundler/gem_tasks'
7
+
8
+ require 'rspec/core/rake_task'
9
+
10
+ begin
11
+ Bundler.setup(:default, :development, :test)
12
+ rescue Bundler::BundlerError => e
13
+ $stderr.puts e.message
14
+ $stderr.puts 'Run `bundle install` to install missing gems'
15
+ exit e.status_code
16
+ end
17
+
18
+ desc 'Tests'
19
+ RSpec::Core::RakeTask.new(:spec) do |spec|
20
+ spec.rspec_opts = '-Ispec'
21
+ # spec.rcov = true
22
+ end
23
+
24
+ task default: [:spec]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "workflow/join"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,94 @@
1
+ require 'workflow'
2
+ require 'workflow/join/version'
3
+
4
+ Workflow::ClassMethods.prepend(Module.new do
5
+ def workflow(&specification)
6
+ # extend instances
7
+ prepend(Module.new do # this should be safe, since there could not be two subsequent workflow DSL
8
+ attr_reader :pending_transitions # FIXME PERSIST!!!
9
+ def guards!
10
+ λλs = spec.guards.map do |inner, outers|
11
+ outers.map do |getter, state|
12
+ guard! inner, getter, state
13
+ end
14
+ end.flatten
15
+ λλs << spec.before_transition_proc if spec.before_transition_proc
16
+ spec.before_transition_proc = ->(from, to, name, *args) { λλs.each { |λ| λ.(from, to, name, *args) } }
17
+ end
18
+
19
+ def guard!(inner, getter, state)
20
+ slave = getter.call(self)
21
+ slave.instance_variable_set(:@☛, (slave.instance_variable_get(:@☛) || []) | [self])
22
+ slave_hook = "on_#{state}_entry".to_sym
23
+ slave.class.prepend(Module.new do
24
+ define_method slave_hook do |old_state, event, *args|
25
+ @☛.each do |master|
26
+ next unless master.pending_transitions.is_a?(Array)
27
+ master.pending_transitions.reject! do |transition|
28
+ begin
29
+ master.send("#{transition}!".to_sym)
30
+ true
31
+ rescue
32
+ false # no transition no cry
33
+ end
34
+ end
35
+ end
36
+ super(old_state, event, *args) rescue nil # no super no cry
37
+ end
38
+ end)
39
+ lambda do |_, to, name, *|
40
+ if to.to_sym == inner && !slave.send("#{state}?".to_sym)
41
+ @pending_transitions ||= []
42
+ @pending_transitions |= [name]
43
+ halt("Waiting for guard workflow to enter “:#{state}” state")
44
+ end
45
+ end
46
+ end
47
+ end)
48
+
49
+ # extend singleton class to update guards in constructor
50
+ singleton_class.prepend(Module.new do
51
+ def new(*)
52
+ super.tap(&:guards!)
53
+ end
54
+ end)
55
+
56
+ super
57
+ end
58
+ end)
59
+
60
+ module Workflow
61
+ module Join
62
+ GUARD_PARAMS_ERROR = 'Either guard instance variable name or a code block is required'.freeze
63
+ GUARD_POINTCUT_ERROR = 'Both :inner and :outer states are required'.freeze
64
+ GUARD_IS_NOT_WORKFLOW = 'Guard given must be a workflow instance'.freeze
65
+
66
+ def guards
67
+ @guards ||= {}
68
+ end
69
+
70
+ def guard(getter = nil, inner: nil, outer: nil)
71
+ fail Workflow::WorkflowDefinitionError, GUARD_PARAMS_ERROR unless !getter.nil? ^ block_given?
72
+ fail Workflow::WorkflowDefinitionError, GUARD_POINTCUT_ERROR unless inner && outer
73
+
74
+ guard = if block_given?
75
+ Proc.new
76
+ else
77
+ g = getter.to_sym
78
+ lambda do |host|
79
+ case
80
+ when /\A@/ =~ g.to_s && host.instance_variable_defined?(g)
81
+ host.instance_variable_get(g)
82
+ when host.methods.include?(g) && host.method(g).arity.zero?
83
+ host.send g
84
+ end.tap do |guard_instance|
85
+ fail Workflow::WorkflowDefinitionError, GUARD_IS_NOT_WORKFLOW unless guard_instance.is_a?(Workflow)
86
+ end
87
+ end
88
+ end
89
+ (guards[inner.to_sym] ||= []) << [guard, outer.to_sym]
90
+ end
91
+ end
92
+ end
93
+
94
+ Workflow::Specification.prepend Workflow::Join
@@ -0,0 +1,5 @@
1
+ module Workflow
2
+ module Join
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'workflow/join/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'workflow-join'
8
+ spec.version = Workflow::Join::VERSION
9
+ spec.authors = ['Aleksei Matiushkin']
10
+ spec.email = ['aleksei.matiushkin@kantox.com']
11
+
12
+ spec.summary = 'Extension to workflow gem providing join functionality for workflows.'
13
+ spec.description = 'Workflow extension that allows to fork workflows with other workflows and join them at specific states.'
14
+ spec.homepage = 'https://github.com/am-kantox/workflow-join'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.10'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'rubocop'
31
+ spec.add_development_dependency 'pry'
32
+
33
+ spec.add_dependency 'workflow', '~> 1.2'
34
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workflow-join
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Aleksei Matiushkin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-16 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '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
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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: workflow
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
97
+ description: Workflow extension that allows to fork workflows with other workflows
98
+ and join them at specific states.
99
+ email:
100
+ - aleksei.matiushkin@kantox.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".rubocop_todo.yml"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/setup
117
+ - lib/workflow/join.rb
118
+ - lib/workflow/join/version.rb
119
+ - workflow-join.gemspec
120
+ homepage: https://github.com/am-kantox/workflow-join
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.8
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Extension to workflow gem providing join functionality for workflows.
144
+ test_files: []