exel 1.3.1 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 942d50f720fa1beb5f52c5723ce1d821435d28eb
4
- data.tar.gz: 0cb7aef5c51a65527872c1cf1fea98de526fc38e
3
+ metadata.gz: 298395fd3c976be0043f2b3834c60da0a8a04a7b
4
+ data.tar.gz: 637b4947a4098049c0778311372f6ff5ad5fd556
5
5
  SHA512:
6
- metadata.gz: c9c02c61169f110c8398f12d2ef89d10a9877625371e98e8db255e5358014dcab9d61ca4f61cdb09bc5e2c3b546c6b0c247b6c2b93d595978db11e08521ca94d
7
- data.tar.gz: e7a29db4087b5e45424c5192d81d59372b7247373f4483077688ffb6f3406fd7db49540818d9e3c404f2c68dabe2309fbe833b945b0164906b6bb0cdff4aca27
6
+ metadata.gz: 0962b4d5a42d1636d8701457af0e0cca956c9137b0c678ff1656f421f97e58c36c38f18a096ab9e60a31efcf76346de177dea5f6a9b522946b47813e9897aee0
7
+ data.tar.gz: 4829d5aef81952163fc7572ecf0f51227ce411672ce50b57007490509fb56f73376cc3ff9a007b6830e802874117701308486ae1ee934beb2c86f7bd1a6f33db
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -22,4 +21,4 @@ tmp
22
21
  mkmf.log
23
22
  .idea
24
23
  *.iml
25
- .ruby-*
24
+ .ruby-*
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ script: bundle exec rspec
3
+ rvm:
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ notifications:
9
+ email:
10
+ recipients:
11
+ - dev@yroo.com
12
+ on_success: change
13
+ on_failure: always
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
  # Specify your gem's dependencies in exel.gemspec
5
5
  gemspec
6
6
 
7
- gem 'codeclimate-test-reporter', group: :test, require: nil
7
+ gem 'codeclimate-test-reporter', '0.6.0', group: :test, require: nil
@@ -0,0 +1,114 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ exel (1.4.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ byebug (10.0.2)
11
+ codeclimate-test-reporter (0.6.0)
12
+ simplecov (>= 0.7.1, < 1.0.0)
13
+ coderay (1.1.2)
14
+ diff-lcs (1.3)
15
+ docile (1.3.1)
16
+ ffi (1.9.23)
17
+ formatador (0.2.5)
18
+ guard (2.14.2)
19
+ formatador (>= 0.2.4)
20
+ listen (>= 2.7, < 4.0)
21
+ lumberjack (>= 1.0.12, < 2.0)
22
+ nenv (~> 0.1)
23
+ notiffany (~> 0.0)
24
+ pry (>= 0.9.12)
25
+ shellany (~> 0.0)
26
+ thor (>= 0.18.1)
27
+ guard-compat (1.2.1)
28
+ guard-rspec (4.7.3)
29
+ guard (~> 2.1)
30
+ guard-compat (~> 1.1)
31
+ rspec (>= 2.99.0, < 4.0)
32
+ guard-rubocop (1.3.0)
33
+ guard (~> 2.0)
34
+ rubocop (~> 0.20)
35
+ json (2.1.0)
36
+ listen (3.1.5)
37
+ rb-fsevent (~> 0.9, >= 0.9.4)
38
+ rb-inotify (~> 0.9, >= 0.9.7)
39
+ ruby_dep (~> 1.2)
40
+ lumberjack (1.0.13)
41
+ method_source (0.9.0)
42
+ nenv (0.3.0)
43
+ notiffany (0.1.1)
44
+ nenv (~> 0.1)
45
+ shellany (~> 0.0)
46
+ parser (2.5.1.0)
47
+ ast (~> 2.4.0)
48
+ powerpack (0.1.1)
49
+ pry (0.11.3)
50
+ coderay (~> 1.1.0)
51
+ method_source (~> 0.9.0)
52
+ pry-byebug (3.6.0)
53
+ byebug (~> 10.0)
54
+ pry (~> 0.10)
55
+ rainbow (2.2.2)
56
+ rake
57
+ rake (10.5.0)
58
+ rb-fsevent (0.10.3)
59
+ rb-inotify (0.9.10)
60
+ ffi (>= 0.5.0, < 2)
61
+ rspec (3.7.0)
62
+ rspec-core (~> 3.7.0)
63
+ rspec-expectations (~> 3.7.0)
64
+ rspec-mocks (~> 3.7.0)
65
+ rspec-core (3.7.1)
66
+ rspec-support (~> 3.7.0)
67
+ rspec-expectations (3.7.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.7.0)
70
+ rspec-mocks (3.7.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.7.0)
73
+ rspec-support (3.7.1)
74
+ rubocop (0.45.0)
75
+ parser (>= 2.3.1.1, < 3.0)
76
+ powerpack (~> 0.1)
77
+ rainbow (>= 1.99.1, < 3.0)
78
+ ruby-progressbar (~> 1.7)
79
+ unicode-display_width (~> 1.0, >= 1.0.1)
80
+ rubocop-rspec-focused (0.1.0)
81
+ rubocop (>= 0.37)
82
+ ruby-progressbar (1.9.0)
83
+ ruby_dep (1.5.0)
84
+ shellany (0.0.1)
85
+ simplecov (0.16.1)
86
+ docile (~> 1.1)
87
+ json (>= 1.8, < 3)
88
+ simplecov-html (~> 0.10.0)
89
+ simplecov-html (0.10.2)
90
+ terminal-notifier (1.6.3)
91
+ terminal-notifier-guard (1.7.0)
92
+ thor (0.20.0)
93
+ unicode-display_width (1.3.3)
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ bundler (~> 1.6)
100
+ codeclimate-test-reporter (= 0.6.0)
101
+ exel!
102
+ guard (~> 2)
103
+ guard-rspec (~> 4)
104
+ guard-rubocop (~> 1)
105
+ pry-byebug
106
+ rake (~> 10)
107
+ rspec (~> 3)
108
+ rubocop (~> 0.45.0)
109
+ rubocop-rspec-focused (~> 0)
110
+ terminal-notifier (~> 1.6.0)
111
+ terminal-notifier-guard (~> 1.7.0)
112
+
113
+ BUNDLED WITH
114
+ 1.16.2
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'guard', '~> 2'
26
26
  spec.add_development_dependency 'guard-rspec', '~> 4'
27
27
  spec.add_development_dependency 'guard-rubocop', '~> 1'
28
- spec.add_development_dependency 'terminal-notifier', '~> 1'
29
- spec.add_development_dependency 'terminal-notifier-guard', '~> 1'
30
- spec.add_development_dependency 'rubocop', '~> 0.39.0'
28
+ spec.add_development_dependency 'terminal-notifier', '~> 1.6.0'
29
+ spec.add_development_dependency 'terminal-notifier-guard', '~> 1.7.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.45.0'
31
31
  spec.add_development_dependency 'rubocop-rspec-focused', '~> 0'
32
32
  spec.add_development_dependency 'pry-byebug'
33
33
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'tempfile'
3
+ require 'securerandom'
3
4
 
4
5
  module EXEL
5
6
  # The +Context+ is the shared memory of a running job. It acts as the source of input to processors and the place for
@@ -48,7 +48,7 @@ module EXEL
48
48
 
49
49
  # Given a context, returns the value that this instance was acting as a placeholder for.
50
50
  def get(context)
51
- keys.reduce(context) { |a, e| a[e] }
51
+ keys.reduce(context) { |acc, elem| acc[elem] }
52
52
  end
53
53
  end
54
54
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rubocop:disable Lint/InheritException
2
3
  module EXEL
3
4
  module Error
4
5
  # If a processor raises a JobTermination exception, the job will immediately stop running without raising anything.
@@ -15,3 +16,4 @@ module EXEL
15
16
  end
16
17
  end
17
18
  end
19
+ # rubocop:enable Lint/InheritException
@@ -12,6 +12,10 @@ module EXEL
12
12
  listeners_for_event(event, context).each { |listener| listener.send(event, context, data) }
13
13
  end
14
14
 
15
+ def self.included(other)
16
+ other.class_eval { attr_reader :context }
17
+ end
18
+
15
19
  private
16
20
 
17
21
  def listeners_for_event(event, context)
@@ -27,6 +27,7 @@ module EXEL
27
27
  def run(dsl_code_or_name, context = {})
28
28
  context = EXEL::Context.new(context) if context.instance_of?(Hash)
29
29
  (ast = parse(dsl_code_or_name)) ? ast.start(context) : raise(%(Job "#{dsl_code_or_name}" not found))
30
+ context
30
31
  end
31
32
 
32
33
  private
@@ -63,7 +63,7 @@ module EXEL
63
63
  def ensure_transaction_duration(duration, start_time)
64
64
  elapsed_time = Time.now.to_f - start_time.to_f
65
65
  time_to_sleep = duration.second.to_f - elapsed_time
66
- sleep(time_to_sleep) if time_to_sleep > 0
66
+ sleep(time_to_sleep) if time_to_sleep.positive?
67
67
  end
68
68
  end
69
69
  end
@@ -12,6 +12,8 @@ module EXEL
12
12
  # * +:delete_resource+ Defaults to true, can be set to false to preserve the original resource. Otherwise, it will
13
13
  # be deleted when splitting is complete
14
14
  # * +:chunk_size+ Set to specify the number of lines that each chunk should contain
15
+ # * +:max_chunks+ Set to specify the maximum number of chunks that should be processed. The resource will not be
16
+ # consumed beyond this limit.
15
17
  class SplitProcessor
16
18
  include EXEL::LoggingHelper
17
19
 
@@ -26,12 +28,16 @@ module EXEL
26
28
  @tempfile_count = 0
27
29
  @context = context
28
30
  @file = context[:resource]
31
+ @max_chunks = @context[:max_chunks] || Float::INFINITY
29
32
  @context[:delete_resource] = true if @context[:delete_resource].nil?
30
33
  end
31
34
 
32
35
  def process(callback)
33
36
  process_file(callback)
34
37
  finish(callback)
38
+ ensure
39
+ @file.close
40
+ File.delete(@file.path) if @context[:delete_resource]
35
41
  end
36
42
 
37
43
  def process_line(line, callback)
@@ -61,6 +67,8 @@ module EXEL
61
67
 
62
68
  CSV.foreach(@file.path, csv_options) do |line|
63
69
  process_line(line, callback)
70
+
71
+ break if @tempfile_count == @max_chunks
64
72
  end
65
73
  rescue CSV::MalformedCSVError => e
66
74
  log_error "CSV::MalformedCSVError => #{e.message}"
@@ -94,7 +102,6 @@ module EXEL
94
102
 
95
103
  def finish(callback)
96
104
  process_line(:eof, callback)
97
- File.delete(@file.path) if @context[:delete_resource]
98
105
  end
99
106
  end
100
107
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module EXEL
3
- VERSION = '1.3.1'
3
+ VERSION = '1.4.0'
4
4
  end
@@ -3,12 +3,20 @@ module EXEL
3
3
  describe Events do
4
4
  class EventTest
5
5
  include Events
6
+
7
+ def initialize(context)
8
+ @context = context
9
+ end
6
10
  end
7
11
 
8
- subject(:events) { EventTest.new }
12
+ subject(:events) { EventTest.new(context) }
9
13
  let(:event_listener) { double(:event_listener) }
10
14
  let(:context) { EXEL::Context.new(Events::LISTENERS_KEY => {event: [event_listener]}) }
11
15
 
16
+ it 'defines an attr_reader for context on the class it is included in' do
17
+ expect(events.context).to eq(context)
18
+ end
19
+
12
20
  describe '#register_listener' do
13
21
  context 'when no listeners have been defined' do
14
22
  let(:context) { EXEL::Context.new }
@@ -34,6 +34,12 @@ module EXEL
34
34
  expect(ast).to receive(:start).with(context)
35
35
  Job.run('code', context)
36
36
  end
37
+
38
+ it 'returns the context' do
39
+ allow(Job::Parser).to receive(:parse).and_return(ast)
40
+ result = Job.run('code', context)
41
+ expect(result).to be(context)
42
+ end
37
43
  end
38
44
 
39
45
  context 'with a job name' do
@@ -49,6 +55,11 @@ module EXEL
49
55
  expect(ast).to receive(:start).with(context)
50
56
  Job.run(:test_job, context)
51
57
  end
58
+
59
+ it 'returns the context' do
60
+ result = Job.run(:test_job, context)
61
+ expect(result).to be(context)
62
+ end
52
63
  end
53
64
 
54
65
  context 'of a undefined job' do
@@ -25,6 +25,7 @@ module EXEL
25
25
  expect(splitter).to receive(:process_line).with(:eof, callback)
26
26
 
27
27
  expect(File).to receive(:delete).with(file.path)
28
+ expect(file).to receive(:close)
28
29
 
29
30
  splitter.process(callback)
30
31
  end
@@ -43,6 +44,37 @@ module EXEL
43
44
  context[:delete_resource] = false
44
45
  splitter.process(callback)
45
46
  end
47
+
48
+ it 'stops splitting at :max_chunks if it is set in the context' do
49
+ allow(CSV).to receive(:foreach).and_yield(['line0']).and_yield(['line1']).and_yield(['line2'])
50
+
51
+ chunk_file = create_file(0)
52
+
53
+ allow(Tempfile).to receive(:new).and_return(chunk_file)
54
+ expect(callback).to receive(:run).once
55
+ allow_any_instance_of(StringIO).to receive(:path).and_return('test path')
56
+
57
+ expect(File).to receive(:delete).with(file.path)
58
+
59
+ context[:chunk_size] = 2
60
+ context[:max_chunks] = 1
61
+ splitter.process(callback)
62
+
63
+ expect(chunk_file.read).to eq("line0\nline1\n")
64
+ end
65
+
66
+ it 'ensures that the source file gets closed and deleted' do
67
+ allow(CSV).to receive(:foreach).and_raise(Interrupt)
68
+
69
+ expect(File).to receive(:delete).with(file.path)
70
+ expect(file).to receive(:close)
71
+
72
+ begin
73
+ splitter.process(callback)
74
+ rescue Interrupt
75
+ nil
76
+ end
77
+ end
46
78
  end
47
79
 
48
80
  describe '#process_line' do
@@ -18,8 +18,6 @@ end
18
18
  class EmailProcessor
19
19
  include EXEL::Events
20
20
 
21
- attr_reader :context
22
-
23
21
  def initialize(context)
24
22
  @context = context
25
23
  @people = context[:people]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yroo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-26 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,42 +100,42 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1'
103
+ version: 1.6.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1'
110
+ version: 1.6.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: terminal-notifier-guard
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '1'
117
+ version: 1.7.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '1'
124
+ version: 1.7.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.39.0
131
+ version: 0.45.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.39.0
138
+ version: 0.45.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rspec-focused
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -176,7 +176,9 @@ files:
176
176
  - ".rspec"
177
177
  - ".rubocop.yml"
178
178
  - ".rubocop_todo.yml"
179
+ - ".travis.yml"
179
180
  - Gemfile
181
+ - Gemfile.lock
180
182
  - Guardfile
181
183
  - LICENSE.txt
182
184
  - README.md
@@ -254,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
256
  version: '0'
255
257
  requirements: []
256
258
  rubyforge_project:
257
- rubygems_version: 2.4.5.1
259
+ rubygems_version: 2.6.13
258
260
  signing_key:
259
261
  specification_version: 4
260
262
  summary: EXEL, the Elastic eXEcution Language