triggerable 0.1.1 → 0.1.2
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 +3 -3
- data/lib/triggerable/rules/automation.rb +1 -1
- data/lib/triggerable/rules/rule.rb +2 -1
- data/lib/triggerable/rules/trigger.rb +1 -1
- data/lib/triggerable/version.rb +1 -1
- data/spec/integration/actions_spec.rb +1 -1
- data/spec/names_spec.rb +19 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe45d698af8f0bf86b0d304e31016a41a8fdd89f
|
4
|
+
data.tar.gz: 472fe481cc00e294f9c52663a004635ffd7a4252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d23f611c146cb4917f40ba009521071b9bd71993836fe71f797488b03005540eed7824999eeef1c28af23a6dd344d9a3420b528bddc458ca7f253486a07bd173
|
7
|
+
data.tar.gz: d7ca5ca5abfe73fcddb25faf05b010a15c56defeb0f41f2466236991cae2538ea1752a5c075c98cb41b3250128bb53cf0dc6b74a6865812fa6f1cc7b9ccf11f9
|
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!(obj)` where obj is a triggered object. Then you can pass a name of your action class instead of do block.
|
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!(trigger_name, obj)` 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! object
|
73
|
+
def run_for! trigger_name, object
|
74
74
|
SmsGateway.send_to object.phone, welcome_text
|
75
75
|
end
|
76
76
|
end
|
data/lib/triggerable/actions.rb
CHANGED
@@ -11,7 +11,7 @@ module Triggerable
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def run_for!(object); end
|
14
|
+
def run_for!(trigger_name, object); end
|
15
15
|
end
|
16
16
|
|
17
17
|
class LambdaAction < Action
|
@@ -19,9 +19,9 @@ module Triggerable
|
|
19
19
|
@block = block
|
20
20
|
end
|
21
21
|
|
22
|
-
def run_for! object
|
22
|
+
def run_for! object, trigger_name
|
23
23
|
proc = @block
|
24
|
-
object.instance_eval { instance_exec(&proc) }
|
24
|
+
object.instance_eval { instance_exec(trigger_name, &proc) }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Rules
|
2
2
|
class Rule
|
3
|
-
attr_accessor :model, :condition, :actions
|
3
|
+
attr_accessor :name, :model, :condition, :actions
|
4
4
|
|
5
5
|
def initialize model, options, block
|
6
6
|
@model = model
|
7
7
|
@condition = Conditions::Condition.build(options[:if])
|
8
|
+
@name = options[:name]
|
8
9
|
@actions = Triggerable::Action.build(block || options[:do])
|
9
10
|
end
|
10
11
|
end
|
data/lib/triggerable/version.rb
CHANGED
data/spec/names_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,7 @@ 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
|
153
154
|
- spec/schema.rb
|
154
155
|
- spec/scopes_spec.rb
|
155
156
|
- spec/spec_helper.rb
|
@@ -186,6 +187,7 @@ test_files:
|
|
186
187
|
- spec/integration/conditions_spec.rb
|
187
188
|
- spec/integration/short_syntax_spec.rb
|
188
189
|
- spec/models.rb
|
190
|
+
- spec/names_spec.rb
|
189
191
|
- spec/schema.rb
|
190
192
|
- spec/scopes_spec.rb
|
191
193
|
- spec/spec_helper.rb
|