transflow 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +45 -0
- data/.rspec +4 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +82 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/transflow.rb +73 -0
- data/lib/transflow/version.rb +3 -0
- data/transflow.gemspec +26 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c18bc0bd37bd89215142adefd13b8a965ea0994
|
4
|
+
data.tar.gz: 7827d58aeef106f8cf0eb6969381b76433f44a4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 531682614e131a47544798c2700fd2c22258b6fa9a61c309515ef5a6bf72404dbd8a4faa29e8111c3f3c930d73243e7791546d1b4d6ff0aaa1699b0755a0833d
|
7
|
+
data.tar.gz: e87f9e64c7249a0c550e43b148391da884bdd90bb23b0eeb3131249961c8fd4882a9e6f0d43a7b98e3fb7513c7d699cf63fa63138df53a184f3dbdfa61621643
|
data/.gitignore
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
=======
|
37
|
+
/.bundle/
|
38
|
+
/.yardoc
|
39
|
+
/Gemfile.lock
|
40
|
+
/_yardoc/
|
41
|
+
/coverage/
|
42
|
+
/doc/
|
43
|
+
/pkg/
|
44
|
+
/spec/reports/
|
45
|
+
/tmp/
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Piotr Solnica
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
[gem]: https://rubygems.org/gems/transflow
|
2
|
+
[travis]: https://travis-ci.org/solnic/transflow
|
3
|
+
[gemnasium]: https://gemnasium.com/solnic/transflow
|
4
|
+
[codeclimate]: https://codeclimate.com/github/solnic/transflow
|
5
|
+
[inchpages]: http://inch-ci.org/github/solnic/transflow
|
6
|
+
|
7
|
+
# Transflow
|
8
|
+
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/transflow.svg)][gem]
|
10
|
+
[![Build Status](https://travis-ci.org/solnic/transflow.svg?branch=master)][travis]
|
11
|
+
[![Dependency Status](https://gemnasium.com/solnic/transflow.png)][gemnasium]
|
12
|
+
[![Code Climate](https://codeclimate.com/github/solnic/transflow/badges/gpa.svg)][codeclimate]
|
13
|
+
[![Test Coverage](https://codeclimate.com/github/solnic/transflow/badges/coverage.svg)][codeclimate]
|
14
|
+
[![Inline docs](http://inch-ci.org/github/solnic/transflow.svg?branch=master)][inchpages]
|
15
|
+
|
16
|
+
Business transaction flow DSL. The aim of this small gem is to provide a simple
|
17
|
+
way of defining complex business transaction flows that include processing by
|
18
|
+
many different objects.
|
19
|
+
|
20
|
+
It is based on the following ideas:
|
21
|
+
|
22
|
+
- a business transaction is a series of operations where each can fail and stop processing
|
23
|
+
- a business transaction resolves its dependencies using an external container object
|
24
|
+
and it doesn't know any details about the individual operation objects except their
|
25
|
+
identifiers
|
26
|
+
- a business transaction can describe the flow on an abstract level without being
|
27
|
+
coupled to any details about how individual operations work
|
28
|
+
- a business transaction doesn't have any state
|
29
|
+
- each operation shouldn't accumulate state, instead it should receive an input and return
|
30
|
+
an output without causing any side-effects
|
31
|
+
- the only interface of a an operation is `#call(input)`
|
32
|
+
- each operation provides a meaningful functionality and can be reused
|
33
|
+
- each operation can broadcast its result (TODO)
|
34
|
+
- external message consumers can listen to a transaction object for specific events (TODO)
|
35
|
+
|
36
|
+
## Why?
|
37
|
+
|
38
|
+
The rationale for this project is quite simple - every use-case in an application
|
39
|
+
can be described as a series of processing steps where some input is turned into
|
40
|
+
an output. Steps can result in triggering additional operations handled by other
|
41
|
+
parts of your application or completely external systems and that can be easily
|
42
|
+
handled by a pub/sub interface.
|
43
|
+
|
44
|
+
It's a clean and simple way of encapsulating complex business logic in your application
|
45
|
+
using simple, stateless objects.
|
46
|
+
|
47
|
+
## Error Handling
|
48
|
+
|
49
|
+
This will be the tricky part - there are scenarios where we need to aggregate
|
50
|
+
errors from multiple steps without stopping the processing. It's not implemented
|
51
|
+
yet but *probably* using pub/sub for that will do the work as we can register an
|
52
|
+
error listener that can simply gather errors and return it as a result.
|
53
|
+
|
54
|
+
## Installation
|
55
|
+
|
56
|
+
Add this line to your application's Gemfile:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
gem 'transflow'
|
60
|
+
```
|
61
|
+
|
62
|
+
And then execute:
|
63
|
+
|
64
|
+
$ bundle
|
65
|
+
|
66
|
+
Or install it yourself as:
|
67
|
+
|
68
|
+
$ gem install transflow
|
69
|
+
|
70
|
+
## Usage
|
71
|
+
|
72
|
+
TODO: Write usage instructions here
|
73
|
+
|
74
|
+
## Development
|
75
|
+
|
76
|
+
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.
|
77
|
+
|
78
|
+
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).
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/transflow.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "transflow"
|
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
data/lib/transflow.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'transproc'
|
2
|
+
require 'transflow/version'
|
3
|
+
|
4
|
+
module Transflow
|
5
|
+
class Transaction
|
6
|
+
attr_reader :handler
|
7
|
+
|
8
|
+
attr_reader :steps
|
9
|
+
|
10
|
+
def initialize(steps, handler)
|
11
|
+
@steps = steps
|
12
|
+
@handler = handler
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(*args)
|
16
|
+
handler.call(*args)
|
17
|
+
end
|
18
|
+
alias_method :[], :call
|
19
|
+
end
|
20
|
+
|
21
|
+
class StepDSL
|
22
|
+
attr_reader :name
|
23
|
+
|
24
|
+
attr_reader :handler
|
25
|
+
|
26
|
+
attr_reader :container
|
27
|
+
|
28
|
+
attr_reader :steps
|
29
|
+
|
30
|
+
def initialize(name, options, container, steps, &block)
|
31
|
+
@name = name
|
32
|
+
@handler = options.fetch(:with)
|
33
|
+
@container = container
|
34
|
+
@steps = steps
|
35
|
+
instance_exec(&block) if block
|
36
|
+
end
|
37
|
+
|
38
|
+
def step(*args, &block)
|
39
|
+
self.class.new(*args, container, steps, &block).call
|
40
|
+
end
|
41
|
+
|
42
|
+
def call
|
43
|
+
steps[name] = container[handler]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class FlowDSL
|
48
|
+
attr_reader :options
|
49
|
+
|
50
|
+
attr_reader :container
|
51
|
+
|
52
|
+
attr_reader :steps
|
53
|
+
|
54
|
+
def initialize(options, &block)
|
55
|
+
@options = options
|
56
|
+
@container = options.fetch(:container)
|
57
|
+
@steps = {}
|
58
|
+
instance_exec(&block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def step(*args, &block)
|
62
|
+
StepDSL.new(*args, container, steps, &block).call
|
63
|
+
end
|
64
|
+
|
65
|
+
def call
|
66
|
+
Transaction.new(steps, steps.values.reverse.reduce(:>>))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def Transflow(options = {}, &block)
|
72
|
+
Transflow::FlowDSL.new(options, &block).call
|
73
|
+
end
|
data/transflow.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'transflow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "transflow"
|
8
|
+
spec.version = Transflow::VERSION
|
9
|
+
spec.authors = ["Piotr Solnica"]
|
10
|
+
spec.email = ["piotr.solnica@gmail.com"]
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.summary = "Business Transaction Flow DSL"
|
14
|
+
spec.homepage = "https://github.com/solnic/transflow"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'transproc', '~> 0.3', '>= 0.3.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Piotr Solnica
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: transproc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.3.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.3.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.10'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.10'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.3'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.3'
|
75
|
+
description:
|
76
|
+
email:
|
77
|
+
- piotr.solnica@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".rspec"
|
84
|
+
- ".travis.yml"
|
85
|
+
- CHANGELOG.md
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- bin/console
|
91
|
+
- bin/setup
|
92
|
+
- lib/transflow.rb
|
93
|
+
- lib/transflow/version.rb
|
94
|
+
- transflow.gemspec
|
95
|
+
homepage: https://github.com/solnic/transflow
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.4.5
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Business Transaction Flow DSL
|
119
|
+
test_files: []
|