bulk_execution 0.0.1
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 +18 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/bulk_execution.gemspec +23 -0
- data/lib/bulk_execution.rb +6 -0
- data/lib/bulk_execution/execution_context.rb +24 -0
- data/lib/bulk_execution/executor.rb +20 -0
- data/lib/bulk_execution/results/result.rb +27 -0
- data/lib/bulk_execution/results/result_set.rb +30 -0
- data/lib/bulk_execution/version.rb +3 -0
- data/spec/bulk_execution/execution_context_spec.rb +35 -0
- data/spec/bulk_execution/executor_spec.rb +32 -0
- data/spec/bulk_execution/results/result_set_spec.rb +66 -0
- data/spec/bulk_execution/results/result_spec.rb +28 -0
- data/spec/support/spec_helper.rb +2 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71cd526e7dfcf85751265c38bf67477ff7350813
|
4
|
+
data.tar.gz: 24e3ea9a896985ed9a362a92ea561212de0ad63b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdcdc13e18e64b13df38a985723efe64021da30cb173382c733ed680d5a64d3e5f168b7b9c3a68ddd3eb49527e65c29732a4a048aeeff98f5cae0452c16be0e6
|
7
|
+
data.tar.gz: 0211d86a6e7bf1777a07fb68c776913a7814a45e775952d4dafd549ec9354c0b25424f1f866444a0ac3d807cb1070e37bff34e2a9ef50da857600b1a46630ae5
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Pete Swan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
[](https://travis-ci.org/gustly/bulk_execution)
|
2
|
+
|
3
|
+
# BulkExecution
|
4
|
+
|
5
|
+
Execute a block over a collection of data keeping track of successes and failures,
|
6
|
+
the data that caused them, and the index of that data within the collection.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'bulk_execution'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install bulk_execution
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
executor = BulkExecution::Exector.new(data)
|
26
|
+
executor.execute do |execution_context|
|
27
|
+
begin
|
28
|
+
result = do_something(execution_context.data)
|
29
|
+
execution_context.record_success(result)
|
30
|
+
rescue
|
31
|
+
execution_context.record_failure($!)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( http://github.com/<my-github-username>/bulk_execution/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bulk_execution/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bulk_execution"
|
8
|
+
spec.version = BulkExecution::VERSION
|
9
|
+
spec.authors = ["Peter Swan"]
|
10
|
+
spec.email = ["pdswan@gmail.com"]
|
11
|
+
spec.summary = %q{Execute a block over a collection storing success and failure with the data that caused it.}
|
12
|
+
spec.homepage = "https://github.com/gustly/bulk_execution"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module BulkExecution
|
2
|
+
class ExecutionContext
|
3
|
+
def initialize(data, index, result_set)
|
4
|
+
@data = data
|
5
|
+
@result_set = result_set
|
6
|
+
@index = index
|
7
|
+
end
|
8
|
+
|
9
|
+
def record_failure(*args)
|
10
|
+
result_set.record_failure(data, index, *args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def record_success(*args)
|
14
|
+
result_set.record_success(data, index, *args)
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :data
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :result_set, :index
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BulkExecution
|
2
|
+
class Executor
|
3
|
+
def initialize(data)
|
4
|
+
@data = data
|
5
|
+
end
|
6
|
+
|
7
|
+
def execute(&block)
|
8
|
+
Results::ResultSet.new.tap do |results|
|
9
|
+
data.each_with_index do |datum, index|
|
10
|
+
block.call(ExecutionContext.new(datum, index, results))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BulkExecution
|
2
|
+
module Results
|
3
|
+
class Result
|
4
|
+
def initialize(data, index, result)
|
5
|
+
raise StandardError, "Abstract base class" if self.class == Result
|
6
|
+
@data = data
|
7
|
+
@index = index
|
8
|
+
@result = result
|
9
|
+
end
|
10
|
+
|
11
|
+
def success?
|
12
|
+
case self
|
13
|
+
when Success then true
|
14
|
+
when Failure then false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :data, :index, :result
|
19
|
+
end
|
20
|
+
|
21
|
+
class Success < Result; end
|
22
|
+
|
23
|
+
class Failure < Result
|
24
|
+
alias_method :error, :result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module BulkExecution
|
2
|
+
module Results
|
3
|
+
class ResultSet
|
4
|
+
def initialize
|
5
|
+
@successes = []
|
6
|
+
@failures = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def record_failure(*args)
|
10
|
+
@failures << Failure.new(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def record_success(*args)
|
14
|
+
@successes << Success.new(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure?
|
18
|
+
failures.any?
|
19
|
+
end
|
20
|
+
|
21
|
+
def success?
|
22
|
+
!failure?
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :failures,
|
26
|
+
:successes
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "support/spec_helper"
|
2
|
+
|
3
|
+
describe BulkExecution::ExecutionContext do
|
4
|
+
let(:execution_context) { BulkExecution::ExecutionContext.new(data, index, result_set) }
|
5
|
+
let(:data) { double(:data) }
|
6
|
+
let(:result_set) { double(:result_set) }
|
7
|
+
let(:index) { double(:index) }
|
8
|
+
|
9
|
+
describe "#record_failure" do
|
10
|
+
let(:failure_arg) { double(:failure_arg) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(result_set).to receive(:record_failure)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "records a failure in the results set" do
|
17
|
+
execution_context.record_failure(failure_arg)
|
18
|
+
expect(result_set).to have_received(:record_failure).with(data, index, failure_arg)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#record_success" do
|
23
|
+
let(:success_arg) { double(:success_arg) }
|
24
|
+
|
25
|
+
before do
|
26
|
+
allow(result_set).to receive(:record_success)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "records a success in teh results set" do
|
30
|
+
execution_context.record_success(success_arg)
|
31
|
+
expect(result_set).to have_received(:record_success).with(data, index, success_arg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "support/spec_helper"
|
2
|
+
|
3
|
+
describe BulkExecution::Executor do
|
4
|
+
let(:bulk_execution) { BulkExecution::Executor.new(data) }
|
5
|
+
let(:block) { Proc.new {} }
|
6
|
+
let(:result_set) { double(:result_set) }
|
7
|
+
|
8
|
+
let(:data) { [datum] }
|
9
|
+
let(:datum) { double(:datum) }
|
10
|
+
|
11
|
+
let(:execution_context) { double(:execution_context) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(BulkExecution::Results::ResultSet).to receive(:new).
|
15
|
+
and_return(result_set)
|
16
|
+
|
17
|
+
allow(block).to receive(:call)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#execute" do
|
21
|
+
it "executes the block over the data" do
|
22
|
+
allow(BulkExecution::ExecutionContext).to receive(:new).
|
23
|
+
with(datum, 0, result_set).
|
24
|
+
and_return(execution_context)
|
25
|
+
|
26
|
+
bulk_execution.execute(&block)
|
27
|
+
|
28
|
+
expect(block).to have_received(:call).with(execution_context)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
describe BulkExecution::Results::ResultSet do
|
2
|
+
let(:result_set) { BulkExecution::Results::ResultSet.new }
|
3
|
+
|
4
|
+
let(:failure) { double(:failure) }
|
5
|
+
let(:failure_data) { double(:failure_data) }
|
6
|
+
let(:index) { double(:index) }
|
7
|
+
let(:error_message) { double(:error_message) }
|
8
|
+
|
9
|
+
let(:success) { double(:success) }
|
10
|
+
let(:success_data) { double(:success_data) }
|
11
|
+
|
12
|
+
let(:success_result) { double(:success_result) }
|
13
|
+
|
14
|
+
describe "#record_failure" do
|
15
|
+
before do
|
16
|
+
allow(BulkExecution::Results::Failure).to receive(:new).
|
17
|
+
with(failure_data, index, error_message).
|
18
|
+
and_return(failure)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "creates a new Failure" do
|
22
|
+
result_set.record_failure(failure_data, index, error_message)
|
23
|
+
expect(result_set.failures).to include(failure)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#record_success" do
|
28
|
+
before do
|
29
|
+
allow(BulkExecution::Results::Success).to receive(:new).
|
30
|
+
with(success_data, index, success_result).
|
31
|
+
and_return(success)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "creates a new Success" do
|
35
|
+
result_set.record_success(success_data, index, success_result)
|
36
|
+
expect(result_set.successes).to include(success)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#failure?" do
|
41
|
+
subject { result_set.failure? }
|
42
|
+
|
43
|
+
context "there are failures" do
|
44
|
+
before { result_set.record_failure(failure_data, index, error_message) }
|
45
|
+
specify { expect(subject).to eq(true) }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "there are no failures" do
|
49
|
+
specify { expect(subject).to eq(false) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#success?" do
|
54
|
+
subject { result_set.success? }
|
55
|
+
|
56
|
+
context "there are failures" do
|
57
|
+
before { result_set.record_failure(failure_data, index, error_message) }
|
58
|
+
specify { expect(subject).to eq(false) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "there are no failures" do
|
62
|
+
specify { expect(subject).to eq(true) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "support/spec_helper"
|
2
|
+
|
3
|
+
describe BulkExecution::Results::Success do
|
4
|
+
let(:success) { BulkExecution::Results::Success.new(data, index, result) }
|
5
|
+
let(:data) { double(:data) }
|
6
|
+
let(:index) { double(:index) }
|
7
|
+
let(:result) { double(:result) }
|
8
|
+
|
9
|
+
describe "#success?" do
|
10
|
+
it "returns true" do
|
11
|
+
expect(success.success?).to eq(true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe BulkExecution::Results::Failure do
|
17
|
+
let(:failure) { BulkExecution::Results::Failure.new(data, index, result) }
|
18
|
+
let(:data) { double(:data) }
|
19
|
+
let(:index) { double(:index) }
|
20
|
+
let(:result) { double(:result) }
|
21
|
+
|
22
|
+
describe "#success?" do
|
23
|
+
it "returns false" do
|
24
|
+
expect(failure.success?).to eq(false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bulk_execution
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Swan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-25 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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:
|
56
|
+
email:
|
57
|
+
- pdswan@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bulk_execution.gemspec
|
69
|
+
- lib/bulk_execution.rb
|
70
|
+
- lib/bulk_execution/execution_context.rb
|
71
|
+
- lib/bulk_execution/executor.rb
|
72
|
+
- lib/bulk_execution/results/result.rb
|
73
|
+
- lib/bulk_execution/results/result_set.rb
|
74
|
+
- lib/bulk_execution/version.rb
|
75
|
+
- spec/bulk_execution/execution_context_spec.rb
|
76
|
+
- spec/bulk_execution/executor_spec.rb
|
77
|
+
- spec/bulk_execution/results/result_set_spec.rb
|
78
|
+
- spec/bulk_execution/results/result_spec.rb
|
79
|
+
- spec/support/spec_helper.rb
|
80
|
+
homepage: https://github.com/gustly/bulk_execution
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.0.3
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Execute a block over a collection storing success and failure with the data
|
104
|
+
that caused it.
|
105
|
+
test_files:
|
106
|
+
- spec/bulk_execution/execution_context_spec.rb
|
107
|
+
- spec/bulk_execution/executor_spec.rb
|
108
|
+
- spec/bulk_execution/results/result_set_spec.rb
|
109
|
+
- spec/bulk_execution/results/result_spec.rb
|
110
|
+
- spec/support/spec_helper.rb
|