lev 4.2.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +33 -0
- data/lib/lev.rb +2 -0
- data/lib/lev/routine.rb +1 -1
- data/lib/lev/version.rb +1 -1
- data/spec/active_job_routines_spec.rb +44 -14
- data/spec/routine_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGMxZTI5ZTEzM2M2Yzc0OWFhMzRmMDg0MDdjZDI3ZmRlNDhmZjM0Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjkwYjg3YTJjOWEyMThlMjk1YjdiY2RmMDI1YmJhNmQ4ZjUyOGQ2Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmM3ZDY1MzdlMWQxMjhjMjFjNDhiYTBjOWY0ZjA1YjVjYTlhMzVjODZjNjg3
|
10
|
+
NGYxOWIwNGQ2OWVmNWE0MjViYTgwYTYxMTZiY2QxYzk4Njg3NWUwZDNkYTk3
|
11
|
+
MmZhMWY1YWEwMjM1ZWFhZGIwZjU5MTY4ZDAyMDFmNWY5MTk2ZGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWJhZTc3NjFlNDc2MTI2MWZiNjg2YjAyNGFkYmE3ZjRhY2QzZWEyZWE1MDEw
|
14
|
+
NDg4ZjMwNGI3NDQ2ZGE0NGI3Mjg0YjFkZDgxZGFlNzA2ZDMxM2NiNjAxNWJk
|
15
|
+
NzMxM2Y2ODJiYzVlNDMxNzQ1ZDk0OWVkZWQyMzYyNTFhZmRiODc=
|
data/README.md
CHANGED
@@ -73,6 +73,31 @@ end
|
|
73
73
|
|
74
74
|
So if you `fatal_error(name: :is_blank)` it will raise `StandardError: "name is blank"`, or `fatal_error(thing: :is_broken, and: :messed_up)` it will raise `StandardError: "thing is broken - and messed up"`
|
75
75
|
|
76
|
+
You can override the global setting in your routine, which also overrides nested routine settings:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
# initializer
|
80
|
+
Lev.configure do |config|
|
81
|
+
config.raise_fatal_errors = false
|
82
|
+
end
|
83
|
+
|
84
|
+
# app/routines/my_routine.rb
|
85
|
+
class MyRoutine
|
86
|
+
lev_routine raise_fatal_errors: true
|
87
|
+
|
88
|
+
uses_routine Tasks::MyTaskRoutine # Still raises despite its setting
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# app/subroutines/tasks/my_task_routine.rb
|
93
|
+
module Tasks
|
94
|
+
class MyTaskRoutine
|
95
|
+
lev_routine raise_fatal_errors: false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
|
76
101
|
Additionally, see below for a discussion on how to transfer errors from ActiveRecord models.
|
77
102
|
|
78
103
|
Any `StandardError` raised within a routine will be caught and transformed into a fatal error with `:kind` set to `:exception`. The caller of this routine can choose to reraise this exception by calling `reraise_exception!` on the returned errors object:
|
@@ -408,6 +433,14 @@ class MyRoutine
|
|
408
433
|
end
|
409
434
|
```
|
410
435
|
|
436
|
+
By default also, jobs use ActiveJob::Base as the class, but you can configure this:
|
437
|
+
|
438
|
+
```ruby
|
439
|
+
Lev.configure do |config|
|
440
|
+
config.active_job_class = TrackableJob
|
441
|
+
end
|
442
|
+
```
|
443
|
+
|
411
444
|
## Handlers
|
412
445
|
|
413
446
|
Handlers are specialized routines that take user input (e.g. form data) and then take an action based on that input. Because all Handlers are Routines, everything discussed above applies to them.
|
data/lib/lev.rb
CHANGED
@@ -55,12 +55,14 @@ module Lev
|
|
55
55
|
attr_accessor :security_transgression_error
|
56
56
|
attr_accessor :illegal_argument_error
|
57
57
|
attr_accessor :raise_fatal_errors
|
58
|
+
attr_accessor :active_job_class
|
58
59
|
|
59
60
|
def initialize
|
60
61
|
@form_error_class = 'error'
|
61
62
|
@security_transgression_error = Lev::SecurityTransgression
|
62
63
|
@illegal_argument_error = Lev::IllegalArgument
|
63
64
|
@raise_fatal_errors = false
|
65
|
+
@active_job_class = defined?(ActiveJob) ? ActiveJob::Base : nil
|
64
66
|
super
|
65
67
|
end
|
66
68
|
end
|
data/lib/lev/routine.rb
CHANGED
@@ -209,7 +209,7 @@ module Lev
|
|
209
209
|
if defined?(ActiveJob)
|
210
210
|
def active_job_class
|
211
211
|
@active_job_class ||= const_set("ActiveJob",
|
212
|
-
Class.new(
|
212
|
+
Class.new(Lev.configuration.active_job_class) do
|
213
213
|
queue_as do
|
214
214
|
parent_routine.active_job_queue
|
215
215
|
end
|
data/lib/lev/version.rb
CHANGED
@@ -4,24 +4,54 @@ require 'spec_helper'
|
|
4
4
|
ActiveJob::Base.queue_adapter = :test
|
5
5
|
ActiveJob::Base.logger = ::Logger.new(nil)
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
RSpec.describe 'ActiveJob routines' do
|
8
|
+
context 'default configuration' do
|
9
|
+
before do
|
10
|
+
Lev.configure { |c| c.active_job_class = ActiveJob::Base } # default
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
13
|
+
class LaterRoutine
|
14
|
+
lev_routine active_job_queue: :something_else
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
protected
|
17
|
+
def exec; end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can perform routines later' do
|
21
|
+
expect {
|
22
|
+
LaterRoutine.perform_later
|
23
|
+
}.to change { ActiveJob::Base.queue_adapter.enqueued_jobs.count }.by(1)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can have the default queue overridden' do
|
18
27
|
LaterRoutine.perform_later
|
19
|
-
|
28
|
+
queue_name = ActiveJob::Base.queue_adapter.enqueued_jobs.first[:queue]
|
29
|
+
expect(queue_name).to eq('something_else')
|
30
|
+
end
|
20
31
|
end
|
21
32
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
33
|
+
context 'specialized configuration' do
|
34
|
+
before do
|
35
|
+
Lev.configure { |c| c.active_job_class = SomeOtherJobBase }
|
36
|
+
end
|
37
|
+
|
38
|
+
class SomeOtherJobBase
|
39
|
+
def self.queue_as(*args); end
|
40
|
+
def self.perform_later; end
|
41
|
+
end
|
42
|
+
|
43
|
+
class NewLaterRoutine
|
44
|
+
lev_routine
|
45
|
+
protected
|
46
|
+
def exec; end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'allows configuration of the class' do
|
50
|
+
allow(SomeOtherJobBase).to receive(:perform_later)
|
51
|
+
|
52
|
+
expect(Lev.configuration.active_job_class).to eq(SomeOtherJobBase)
|
53
|
+
NewLaterRoutine.perform_later
|
54
|
+
expect(SomeOtherJobBase).to have_received(:perform_later)
|
55
|
+
end
|
26
56
|
end
|
27
57
|
end
|
data/spec/routine_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe Lev::Routine do
|
|
35
35
|
it 'allows not raising fatal errors to be overridden' do
|
36
36
|
stub_const 'NestedFatalError', Class.new
|
37
37
|
NestedFatalError.class_eval {
|
38
|
-
lev_routine
|
38
|
+
lev_routine raise_fatal_errors: false # testing that parent overrides
|
39
39
|
|
40
40
|
def exec
|
41
41
|
fatal_error(code: :its_broken)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Slavinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|