triggerable 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/triggerable/actions.rb +5 -1
- data/lib/triggerable/version.rb +1 -1
- metadata +1 -3
- data/spec/names_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50059bb341314ac2546438f420f9162ec1661715
|
4
|
+
data.tar.gz: 3d523b78004b5820f2a27a08e5736c2efb49abfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed94209ac03b2fb05b95c4a11e087493c6017c6f015bf3a3e6013516c8c273e453d0ff1250287fc8da95bf4a52347720095e44be15d716e587484fd263b5b76e
|
7
|
+
data.tar.gz: 408aca735a06cdd505ab0280d175b815586245d46df7e4fe6033042fbb3e37bcbc022ba81e6e0b88e5941cfe9fdebf7de900fe47c2b355f07a666924a8cafafc
|
data/README.md
CHANGED
@@ -66,11 +66,11 @@ trigger on: :after_update, if: -> { orders.any? } do
|
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
|
-
If you need to share logic between triggers/automations bodies you can move it into separate class. It should be inherited from `Triggerable::Action` and implement a single method `run_for!(
|
69
|
+
If you need to share logic between triggers/automations bodies you can move it into separate class. It should be inherited from `Triggerable::Action` and implement a single method `run_for!(obj, trigger_name)` where trigger_name is a string passed to rule in :name option and obj is a triggered object. Then you can pass a name of your action class instead of do block.
|
70
70
|
|
71
71
|
```ruby
|
72
72
|
class SendWelcomeSms < Triggerable::Action
|
73
|
-
def run_for!
|
73
|
+
def run_for! object, trigger_name
|
74
74
|
SmsGateway.send_to object.phone, welcome_text
|
75
75
|
end
|
76
76
|
end
|
data/lib/triggerable/actions.rb
CHANGED
@@ -21,7 +21,11 @@ module Triggerable
|
|
21
21
|
|
22
22
|
def run_for! object, trigger_name
|
23
23
|
proc = @block
|
24
|
-
object.instance_eval
|
24
|
+
object.instance_eval do
|
25
|
+
PaperTrail.whodunnit = trigger_name if defined?(PaperTrail)
|
26
|
+
instance_exec(&proc)
|
27
|
+
PaperTrail.whodunnit = nil if defined?(PaperTrail)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
data/lib/triggerable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triggerable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
@@ -150,7 +150,6 @@ files:
|
|
150
150
|
- spec/integration/conditions_spec.rb
|
151
151
|
- spec/integration/short_syntax_spec.rb
|
152
152
|
- spec/models.rb
|
153
|
-
- spec/names_spec.rb
|
154
153
|
- spec/schema.rb
|
155
154
|
- spec/scopes_spec.rb
|
156
155
|
- spec/spec_helper.rb
|
@@ -187,7 +186,6 @@ test_files:
|
|
187
186
|
- spec/integration/conditions_spec.rb
|
188
187
|
- spec/integration/short_syntax_spec.rb
|
189
188
|
- spec/models.rb
|
190
|
-
- spec/names_spec.rb
|
191
189
|
- spec/schema.rb
|
192
190
|
- spec/scopes_spec.rb
|
193
191
|
- spec/spec_helper.rb
|
data/spec/names_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Naming' do
|
4
|
-
before(:each) do
|
5
|
-
Engine.clear
|
6
|
-
TestTask.destroy_all
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'trigger name is available in body' do
|
10
|
-
name = 'Create followup'
|
11
|
-
TestTask.trigger name: name, on: :before_update, if: { status: { is: 'solved' } } do |trigger_name|
|
12
|
-
self.kind = trigger_name
|
13
|
-
end
|
14
|
-
|
15
|
-
task = TestTask.create
|
16
|
-
task.update_attributes status: 'solved'
|
17
|
-
expect(task.kind).to eq(name)
|
18
|
-
end
|
19
|
-
end
|