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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49133136262b0acdb06a687a60c018db263d8a04
4
- data.tar.gz: 4385cdecc97b3520259cd1c59f60228e00a8fd87
3
+ metadata.gz: fe45d698af8f0bf86b0d304e31016a41a8fdd89f
4
+ data.tar.gz: 472fe481cc00e294f9c52663a004635ffd7a4252
5
5
  SHA512:
6
- metadata.gz: 1b8e5ab08307ff8886086dab858e95b9a3df770fa59ea8296a331d16b6397cf18643231a2351b987787aedc61961a7a44db3628811d4f40968150fad7fd5a8ab
7
- data.tar.gz: bd7b0953dba3f5e765b13a4d3460e4612c33075748417bfe89ab602b9fa3a639b0e2d579992fe7190ad6f2e06c16c3e61fba92454feca21ba3702e6289def0c3
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
@@ -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
@@ -7,7 +7,7 @@ module Rules
7
7
  ids = ParentModel.connection.execute(query).map { |r| r['id'] }
8
8
  models = model.where(id: ids)
9
9
 
10
- models.each {|o| actions.each {|a| a.run_for!(o)} }
10
+ models.each {|object| actions.each {|a| a.run_for!(object, name)} }
11
11
  end
12
12
  end
13
13
  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
@@ -8,7 +8,7 @@ module Rules
8
8
  end
9
9
 
10
10
  def execute! object
11
- actions.each {|a| a.run_for!(object)} if condition.true_for?(object)
11
+ actions.each {|a| a.run_for!(object, name)} if condition.true_for?(object)
12
12
  end
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Triggerable
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -7,7 +7,7 @@ describe 'Actions' do
7
7
  end
8
8
 
9
9
  class CreateFollowUp < Triggerable::Action
10
- def run_for! task
10
+ def run_for! trigger_name, task
11
11
  TestTask.create kind: 'follow up'
12
12
  end
13
13
  end
@@ -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.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-05 00:00:00.000000000 Z
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