rules_engine 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/VERSION +1 -1
  2. data/lib/rules_engine/process/runner.rb +81 -75
  3. data/lib/rules_engine/process/runner/db_runner.rb +2 -2
  4. data/lib/rules_engine/rule/definition.rb +1 -1
  5. data/lib/rules_engine_view/alerts.rb +3 -4
  6. data/lib/rules_engine_view/navigate.rb +2 -2
  7. data/rails_generators/manifests/complex.rb +6 -6
  8. data/rails_generators/manifests/complex.yml +6 -6
  9. data/rails_generators/manifests/simple.rb +5 -5
  10. data/rails_generators/manifests/simple.yml +5 -5
  11. data/rails_generators/templates/app/controllers/re_plans_controller.rb +2 -2
  12. data/rails_generators/templates/app/models/re_plan.rb +7 -2
  13. data/rails_generators/templates/app/models/re_workflow.rb +8 -1
  14. data/rails_generators/templates/app/rules/complex.rb +21 -21
  15. data/rails_generators/templates/app/rules/simple.rb +4 -4
  16. data/rails_generators/templates/app/views/re_plan_workflows/edit.js.erb +2 -0
  17. data/rails_generators/templates/app/views/re_plan_workflows/new.js.erb +2 -0
  18. data/rails_generators/templates/app/views/re_plans/_menu.html.erb +6 -8
  19. data/rails_generators/templates/app/views/re_plans/change.html.erb +1 -0
  20. data/rails_generators/templates/app/views/re_plans/edit.js.erb +2 -0
  21. data/rails_generators/templates/app/views/re_plans/new.js.erb +2 -0
  22. data/rails_generators/templates/app/views/re_rules/complex/_edit.html.erb +1 -0
  23. data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_form.html.erb +10 -10
  24. data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_form_word.html.erb +1 -1
  25. data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_help.html.erb +0 -0
  26. data/rails_generators/templates/app/views/re_rules/complex/_new.html.erb +1 -0
  27. data/rails_generators/templates/app/views/re_rules/simple/_edit.html.erb +1 -0
  28. data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_form.html.erb +0 -0
  29. data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_help.html.erb +0 -0
  30. data/rails_generators/templates/app/views/re_rules/simple/_new.html.erb +1 -0
  31. data/rails_generators/templates/app/views/re_workflows/edit.js.erb +2 -0
  32. data/rails_generators/templates/app/views/re_workflows/new.js.erb +3 -1
  33. data/rails_generators/templates/lib/tasks/rules_engine.rake +4 -4
  34. data/rails_generators/templates/public/javascripts/rules_engine/re_plan_change.js +13 -1
  35. data/rails_generators/templates/public/stylesheets/rules_engine/screen.css +2 -2
  36. data/rails_generators/templates/spec/controllers/re_plans_controller_spec.rb +0 -8
  37. data/rails_generators/templates/spec/lib/rules/complex_spec.rb +70 -69
  38. data/rails_generators/templates/spec/lib/rules/simple_spec.rb +8 -8
  39. data/rails_generators/templates/spec/models/re_plan_spec.rb +3 -3
  40. data/rails_generators/templates/spec/models/re_rule_spec.rb +14 -19
  41. data/rails_generators/templates/spec/models/re_workflow_spec.rb +9 -0
  42. data/spec/railsenv/log/debug.log +4050 -0
  43. data/spec/railsenv/log/test.log +592 -0
  44. data/spec/rules_engine/process/runner/db_runner_spec.rb +15 -16
  45. data/spec/rules_engine/process/runner_spec.rb +166 -113
  46. data/spec/rules_engine/rule/definition_spec.rb +2 -2
  47. metadata +13 -13
  48. data/rails_generators/templates/app/views/re_rule_definitions/complex/_edit.html.erb +0 -1
  49. data/rails_generators/templates/app/views/re_rule_definitions/complex/_new.html.erb +0 -1
  50. data/rails_generators/templates/app/views/re_rule_definitions/simple/_edit.html.erb +0 -1
  51. data/rails_generators/templates/app/views/re_rule_definitions/simple/_new.html.erb +0 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -40,8 +40,32 @@ module RulesEngine
40
40
  # 0
41
41
  end
42
42
 
43
- def run(process_id, plan, data = {})
44
- _run_plan(process_id, plan, data)
43
+ def run_plan(process_id, plan, data = {})
44
+ RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : started", RulesEngine::Process::AUDIT_INFO)
45
+
46
+ success = _run_plan_workflow(process_id, plan, plan["workflow"], data)
47
+
48
+ if success
49
+ RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : success", RulesEngine::Process::AUDIT_SUCCESS)
50
+ else
51
+ RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : failure", RulesEngine::Process::AUDIT_FAILURE)
52
+ end
53
+
54
+ success
55
+ end
56
+
57
+ def run_workflow(process_id, plan, workflow_name, data = {})
58
+ RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : started", RulesEngine::Process::AUDIT_INFO)
59
+
60
+ success = _run_plan_workflow(process_id, plan, workflow_name, data)
61
+
62
+ if success
63
+ RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : success", RulesEngine::Process::AUDIT_SUCCESS)
64
+ else
65
+ RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : failure", RulesEngine::Process::AUDIT_FAILURE)
66
+ end
67
+
68
+ success
45
69
  end
46
70
 
47
71
  def status(process_id)
@@ -56,91 +80,73 @@ module RulesEngine
56
80
  end
57
81
 
58
82
  protected
59
- def _run_plan(process_id, plan, data = {})
83
+ def _run_plan_workflow(process_id, plan, workflow_name, data = {})
60
84
 
61
- RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : started", RulesEngine::Process::AUDIT_INFO)
62
-
63
85
  workflow_count = 0
64
- done = false
65
- error = false
66
-
67
- first_workflow = plan['first_workflow']
68
- if (first_workflow.blank? || plan["workflow_#{first_workflow}"].nil?)
69
- RulesEngine::Process.auditor.audit(process_id, "First Workflow : #{first_workflow} : missing", RulesEngine::Process::AUDIT_FAILURE)
70
- error = done = true
71
- end
72
-
73
- current_workflow = first_workflow
74
- next_workflow = ""
75
- while (!done && workflow_count < @@max_workflows)
86
+ while (workflow_count < @@max_workflows)
76
87
  workflow_count += 1
77
-
78
- RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : started", RulesEngine::Process::AUDIT_INFO)
79
-
80
- workflow = plan["workflow_#{current_workflow}"]
88
+
89
+ workflow = plan["workflow_#{workflow_name}"]
81
90
  if workflow.nil?
82
- RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : not found", RulesEngine::Process::AUDIT_FAILURE)
83
- error = done = true
84
- break
91
+ RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : not found", RulesEngine::Process::AUDIT_FAILURE)
92
+ return false;
85
93
  end
86
-
87
- workflow["rules"].each do | workflow_rule |
88
- rule_class = RulesEngine::Discovery.rule_class(workflow_rule["rule_class_name"])
89
- unless rule_class
90
- RulesEngine::Process.auditor.audit(process_id, "Rule : #{workflow_rule["rule_class_name"]} : not found", RulesEngine::Process::AUDIT_FAILURE)
91
- error = done = true
92
- break
93
- end
94
- rule = rule_class.new
95
- rule.data = workflow_rule["data"]
96
94
 
97
- RulesEngine::Process.auditor.audit(process_id, "Rule : #{rule.title} : starting")
98
- rule_outcome = rule.process(process_id, data)
99
- RulesEngine::Process.auditor.audit(process_id, "Rule : #{rule.title} : finished")
95
+ rule_outcome = _run_workflow_rules(process_id, plan, workflow, data)
96
+
97
+ if rule_outcome.nil?
98
+ return true
99
+ elsif rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_SUCCESS
100
+ return true
101
+ elsif rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE
102
+ return false
103
+ elsif rule_outcome.outcome == RulesEngine::Rule::Outcome::START_WORKFLOW
104
+ workflow_name = rule_outcome.workflow_code
105
+ else # rule_outcome.outcome == RulesEngine::Rule::Outcome::NEXT
106
+ return true
107
+ end
108
+ end
100
109
 
101
- if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_SUCCESS
102
- RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : stop success", RulesEngine::Process::AUDIT_SUCCESS)
103
- done = true
104
- break
105
- end
106
-
107
- if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE
108
- RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : stop failure", RulesEngine::Process::AUDIT_FAILURE)
109
- error = done = true
110
- break
111
- end
110
+ RulesEngine::Process.auditor.audit(process_id, "Maximum workflow depth #{@@max_workflows} exceeded", RulesEngine::Process::PROCESS_STATUS_FAILURE)
111
+ return false
112
+ end
112
113
 
113
- if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::START_WORKFLOW
114
- RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : start next workflow - #{rule_outcome.workflow_code}", RulesEngine::Process::AUDIT_INFO)
115
- next_workflow = rule_outcome.workflow_code
116
- break
117
- end
118
- end
114
+ def _run_workflow_rules(process_id, plan, workflow, data = {})
119
115
 
120
- if next_workflow.blank?
121
- current_workflow = workflow["next_workflow"]
122
- else
123
- current_workflow = next_workflow
124
- end
116
+ RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : started", RulesEngine::Process::AUDIT_INFO)
125
117
 
126
- if current_workflow.blank?
127
- done = true
128
- break
129
- end
130
- end
131
-
132
- if workflow_count >= @@max_workflows
133
- RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : error - Maximum workflow depth #{@@max_workflows} exceeded", RulesEngine::Process::PROCESS_STATUS_FAILURE)
134
- error = true
135
- end
118
+ workflow["rules"].each do | workflow_rule |
119
+ rule_class = RulesEngine::Discovery.rule_class(workflow_rule["rule_class_name"])
120
+ unless rule_class
121
+ RulesEngine::Process.auditor.audit(process_id, "Rule : #{workflow_rule["rule_class_name"]} : not found", RulesEngine::Process::AUDIT_FAILURE)
122
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
123
+ end
124
+
125
+ rule = rule_class.new
126
+ rule.data = workflow_rule["data"]
127
+
128
+ RulesEngine::Process.auditor.audit(process_id, "Rule : #{rule.title} : starting")
129
+ rule_outcome = rule.process(process_id, plan, data)
130
+ RulesEngine::Process.auditor.audit(process_id, "Rule : #{rule.title} : finished")
136
131
 
137
- if error
138
- RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : failure", RulesEngine::Process::AUDIT_FAILURE)
139
- else
140
- RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : success", RulesEngine::Process::AUDIT_SUCCESS)
141
- end
132
+ if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_SUCCESS
133
+ RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : stop success", RulesEngine::Process::AUDIT_SUCCESS)
134
+ return rule_outcome
135
+ end
142
136
 
143
- !error
137
+ if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE
138
+ RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : stop failure", RulesEngine::Process::AUDIT_FAILURE)
139
+ return rule_outcome
140
+ end
141
+
142
+ if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::START_WORKFLOW
143
+ RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : start next workflow - #{rule_outcome.workflow_code}", RulesEngine::Process::AUDIT_INFO)
144
+ return rule_outcome
145
+ end
146
+ end
147
+
148
+ RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : stop success", RulesEngine::Process::AUDIT_SUCCESS)
149
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
144
150
  end
145
151
  end
146
152
  end
@@ -31,7 +31,7 @@ module RulesEngine
31
31
  ReProcessRun.create(:process_status => RulesEngine::Process::PROCESS_STATUS_NONE).id
32
32
  end
33
33
 
34
- def run(process_id, plan, data = {})
34
+ def run_plan(process_id, plan, data = {})
35
35
  re_process = ReProcessRun.find_by_id(process_id)
36
36
 
37
37
  if re_process.nil?
@@ -41,7 +41,7 @@ module RulesEngine
41
41
 
42
42
  re_process.update_attributes(:plan_code => plan["code"], :plan_version => plan["version"], :started_at => Time.now.utc, :process_status => RulesEngine::Process::PROCESS_STATUS_RUNNING)
43
43
 
44
- success = _run_plan(process_id, plan, data)
44
+ success = super(process_id, plan, data)
45
45
 
46
46
  re_process.update_attributes(:finished_at => Time.now.utc, :process_status => success ? RulesEngine::Process::PROCESS_STATUS_SUCCESS : RulesEngine::Process::PROCESS_STATUS_FAILURE)
47
47
 
@@ -76,7 +76,7 @@ module RulesEngine
76
76
  # execute the rule
77
77
  # return an RulesEngine::Rule::Outcome object to define what to do next
78
78
  # if nil to continue to the next rule
79
- def process(process_id, data)
79
+ def process(process_id, plan, data)
80
80
  # process.audit("process #{title}", RulesEngine::Process::AUDIT_INFO)
81
81
  # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
82
82
  # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
@@ -7,7 +7,7 @@ module RulesEngineView
7
7
  unless flash[:error].blank?
8
8
  result << '<div class="error"><strong>Error : </strong><span>'
9
9
  result << flash.delete(:error)
10
- result << '</span></div>'
10
+ result << '</span><a class="re-alert-close" href="#">Close</a></div>'
11
11
 
12
12
  flash.delete(:success)
13
13
  flash.delete(:notice)
@@ -16,7 +16,7 @@ module RulesEngineView
16
16
  unless flash[:success].blank?
17
17
  result << '<div class="success"><strong>Success : </strong><span>'
18
18
  result << flash.delete(:success)
19
- result << '</span></div>'
19
+ result << '</span><a class="re-alert-close" href="#">Close</a></div>'
20
20
 
21
21
  flash.delete(:notice)
22
22
  end
@@ -24,9 +24,8 @@ module RulesEngineView
24
24
  unless flash[:notice].blank?
25
25
  result << '<div class="notice"><strong>Warning : </strong><span>'
26
26
  result << flash.delete(:notice)
27
- result << '</span></div>'
27
+ result << '</span><a class="re-alert-close" href="#">Close</a></div>'
28
28
  end
29
-
30
29
  result << '</div>'
31
30
 
32
31
  return result
@@ -12,7 +12,7 @@ module RulesEngineView
12
12
  result << "<em>"
13
13
  result << "#{links[-1]}"
14
14
  result << "</em>"
15
- result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-1] == links[0]
15
+ # result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-1] == links[0]
16
16
  result << '</div>'
17
17
  result
18
18
  end
@@ -28,7 +28,7 @@ module RulesEngineView
28
28
  result << "<em>"
29
29
  result << "#{links[-2]}"
30
30
  result << "</em>"
31
- result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-2] == links[0]
31
+ # result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-2] == links[0]
32
32
 
33
33
  result << "<div class='re-breadcrumb-right'>#{links[-1]}</div>"
34
34
  result << '</div>'
@@ -3,7 +3,7 @@ class ComplexManifest
3
3
 
4
4
  %W(
5
5
  app/rules
6
- app/views/re_rule_definitions/#{rule_name}
6
+ app/views/re_rules/#{rule_name}
7
7
  spec/lib/rules
8
8
  ).each do |dirname|
9
9
  m.directory dirname
@@ -15,11 +15,11 @@ class ComplexManifest
15
15
  end
16
16
 
17
17
  m.template "app/rules/complex.rb", "app/rules/#{rule_name}.rb"
18
- m.template "app/views/re_rule_definitions/complex/_edit.html.erb", "app/views/re_rule_definitions/#{rule_name}/_edit.html.erb"
19
- m.template "app/views/re_rule_definitions/complex/_form.html.erb", "app/views/re_rule_definitions/#{rule_name}/_form.html.erb"
20
- m.template "app/views/re_rule_definitions/complex/_form_word.html.erb", "app/views/re_rule_definitions/#{rule_name}/_form_word.html.erb"
21
- m.template "app/views/re_rule_definitions/complex/_help.html.erb", "app/views/re_rule_definitions/#{rule_name}/_help.html.erb"
22
- m.template "app/views/re_rule_definitions/complex/_new.html.erb", "app/views/re_rule_definitions/#{rule_name}/_new.html.erb"
18
+ m.template "app/views/re_rules/complex/_edit.html.erb", "app/views/re_rules/#{rule_name}/_edit.html.erb"
19
+ m.template "app/views/re_rules/complex/_form.html.erb", "app/views/re_rules/#{rule_name}/_form.html.erb"
20
+ m.template "app/views/re_rules/complex/_form_word.html.erb", "app/views/re_rules/#{rule_name}/_form_word.html.erb"
21
+ m.template "app/views/re_rules/complex/_help.html.erb", "app/views/re_rules/#{rule_name}/_help.html.erb"
22
+ m.template "app/views/re_rules/complex/_new.html.erb", "app/views/re_rules/#{rule_name}/_new.html.erb"
23
23
  m.template "spec/lib/rules/complex_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
24
24
 
25
25
  end
@@ -8,13 +8,13 @@ templates :
8
8
  - Complex : rule_class
9
9
 
10
10
  directories :
11
- - app/views/re_rule_definitions/complex
11
+ - app/views/re_rules/complex
12
12
 
13
13
  files :
14
14
  - app/rules/complex.rb
15
- - app/views/re_rule_definitions/complex/_edit.html.erb
16
- - app/views/re_rule_definitions/complex/_form_word.html.erb
17
- - app/views/re_rule_definitions/complex/_form.html.erb
18
- - app/views/re_rule_definitions/complex/_help.html.erb
19
- - app/views/re_rule_definitions/complex/_new.html.erb
15
+ - app/views/re_rules/complex/_edit.html.erb
16
+ - app/views/re_rules/complex/_form_word.html.erb
17
+ - app/views/re_rules/complex/_form.html.erb
18
+ - app/views/re_rules/complex/_help.html.erb
19
+ - app/views/re_rules/complex/_new.html.erb
20
20
  - spec/lib/rules/complex_spec.rb
@@ -3,7 +3,7 @@ class SimpleManifest
3
3
 
4
4
  %W(
5
5
  app/rules
6
- app/views/re_rule_definitions/#{rule_name}
6
+ app/views/re_rules/#{rule_name}
7
7
  spec/lib/rules
8
8
  ).each do |dirname|
9
9
  m.directory dirname
@@ -15,10 +15,10 @@ class SimpleManifest
15
15
  end
16
16
 
17
17
  m.template "app/rules/simple.rb", "app/rules/#{rule_name}.rb"
18
- m.template "app/views/re_rule_definitions/simple/_edit.html.erb", "app/views/re_rule_definitions/#{rule_name}/_edit.html.erb"
19
- m.template "app/views/re_rule_definitions/simple/_form.html.erb", "app/views/re_rule_definitions/#{rule_name}/_form.html.erb"
20
- m.template "app/views/re_rule_definitions/simple/_help.html.erb", "app/views/re_rule_definitions/#{rule_name}/_help.html.erb"
21
- m.template "app/views/re_rule_definitions/simple/_new.html.erb", "app/views/re_rule_definitions/#{rule_name}/_new.html.erb"
18
+ m.template "app/views/re_rules/simple/_edit.html.erb", "app/views/re_rules/#{rule_name}/_edit.html.erb"
19
+ m.template "app/views/re_rules/simple/_form.html.erb", "app/views/re_rules/#{rule_name}/_form.html.erb"
20
+ m.template "app/views/re_rules/simple/_help.html.erb", "app/views/re_rules/#{rule_name}/_help.html.erb"
21
+ m.template "app/views/re_rules/simple/_new.html.erb", "app/views/re_rules/#{rule_name}/_new.html.erb"
22
22
  m.template "spec/lib/rules/simple_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
23
23
 
24
24
  end
@@ -8,13 +8,13 @@ templates :
8
8
  - RuleSimple : rule_class
9
9
 
10
10
  directories :
11
- - app/views/re_rule_definitions/simple
11
+ - app/views/re_rules/simple
12
12
 
13
13
  files :
14
14
  - app/rules/simple.rb
15
- - app/views/re_rule_definitions/simple/_edit.html.erb
16
- - app/views/re_rule_definitions/simple/_form.html.erb
17
- - app/views/re_rule_definitions/simple/_help.html.erb
18
- - app/views/re_rule_definitions/simple/_new.html.erb
15
+ - app/views/re_rules/simple/_edit.html.erb
16
+ - app/views/re_rules/simple/_form.html.erb
17
+ - app/views/re_rules/simple/_help.html.erb
18
+ - app/views/re_rules/simple/_new.html.erb
19
19
  - spec/lib/rules/simple_spec.rb
20
20
 
@@ -86,8 +86,8 @@ class RePlansController < ApplicationController
86
86
  end
87
87
 
88
88
  def publish
89
- if @re_plan.plan_error || params['tag'].blank?
90
- flash[:error] = 'Cannot Publish Plan.'
89
+ if params['tag'].blank?
90
+ flash[:error] = 'Tag Required.'
91
91
  else
92
92
  @re_plan.plan_version = RulesEngine::Publish.publisher.publish(@re_plan.code, params['tag'], @re_plan.publish)
93
93
  @re_plan.plan_status = RePlan::PLAN_STATUS_PUBLISHED
@@ -38,7 +38,7 @@ class RePlan < ActiveRecord::Base
38
38
  "code" => code,
39
39
  "title" => title,
40
40
  "description" => description,
41
- "first_workflow" => re_workflows.empty? ? '' : re_workflows[0].code,
41
+ "workflow" => re_workflows.empty? ? '' : re_workflows[0].code,
42
42
  }
43
43
  re_workflows.each_with_index do | re_workflow, index |
44
44
  data["workflow_#{re_workflow.code}"] = re_workflow.publish
@@ -59,7 +59,7 @@ class RePlan < ActiveRecord::Base
59
59
  self.description = rule_data["description"]
60
60
 
61
61
  orig_re_workflows = []
62
- workflow_data = rule_data["workflow_#{rule_data["first_workflow"]}"]
62
+ workflow_data = rule_data["workflow_#{rule_data["workflow"]}"]
63
63
  while (workflow_data && orig_re_workflows.length < 500)
64
64
  workflow_code = workflow_data["code"]
65
65
  re_workflow = ReWorkflow.find_by_code(workflow_code) || ReWorkflow.new
@@ -93,7 +93,12 @@ class RePlan < ActiveRecord::Base
93
93
  return if self.re_workflows.empty? || self.re_workflows[0] == re_workflow
94
94
  re_plan_workflow = re_plan_workflows.detect { | re_plan_workflow | re_plan_workflow.re_workflow_id == re_workflow.id}
95
95
  return unless re_plan_workflow
96
+
96
97
  re_plan_workflow.move_to_top
98
+
99
+ self.re_plan_workflows(true)
100
+ self.re_workflows(true)
101
+
97
102
  changed!
98
103
  end
99
104
 
@@ -10,11 +10,18 @@ class ReWorkflow < ActiveRecord::Base
10
10
  named_scope :order_code, :order => 're_workflows.code ASC'
11
11
  named_scope :order_title, :order => 're_workflows.title ASC'
12
12
 
13
- before_save :before_save_workflow
13
+ before_save :before_save_workflow
14
+ before_destroy :before_destroy_workflow
14
15
 
15
16
  def before_save_workflow
16
17
  self.changed! if changes.detect { |change| !ignore_attributes.include?(change[0])}
17
18
  end
19
+
20
+ def before_destroy_workflow
21
+ re_plans.each do |re_plan|
22
+ re_plan.changed!
23
+ end
24
+ end
18
25
 
19
26
  def code=(new_code)
20
27
  self[:code] = new_code.strip.downcase.gsub(/[^a-zA-Z0-9]+/i, '_') if new_code && new_record?
@@ -2,9 +2,9 @@ module RulesEngine
2
2
  module Rule
3
3
  class <%=rule_class%> < RulesEngine::Rule::Definition
4
4
 
5
- attr_reader :words
5
+ attr_reader :match_words
6
6
  attr_reader :workflow_action
7
- attr_reader :workflow
7
+ attr_reader :workflow_code
8
8
 
9
9
  ##################################################################
10
10
  # class options
@@ -12,9 +12,9 @@ module RulesEngine
12
12
  {
13
13
  :group => 'General',
14
14
  :display_name => '<%=rule_class%>',
15
- :help_partial => '/re_rule_definitions/<%=rule_name%>/help',
16
- :new_partial => '/re_rule_definitions/<%=rule_name%>/new',
17
- :edit_partial => '/re_rule_definitions/<%=rule_name%>/edit'
15
+ :help_partial => '/re_rules/<%=rule_name%>/help',
16
+ :new_partial => '/re_rules/<%=rule_name%>/new',
17
+ :edit_partial => '/re_rules/<%=rule_name%>/edit'
18
18
  }
19
19
 
20
20
  ##################################################################
@@ -22,11 +22,11 @@ module RulesEngine
22
22
  def data= data
23
23
  if data.nil?
24
24
  @title = nil
25
- @words = nil
25
+ @match_words = nil
26
26
  @workflow_action = 'continue'
27
- @workflow = nil
27
+ @workflow_code = nil
28
28
  else
29
- @title, @words, @workflow_action, @workflow = ActiveSupport::JSON.decode(data)
29
+ @title, @match_words, @workflow_action, @workflow_code = ActiveSupport::JSON.decode(data)
30
30
  end
31
31
  end
32
32
 
@@ -37,11 +37,11 @@ module RulesEngine
37
37
  end
38
38
 
39
39
  def summary
40
- "Match the #{words.size == 1 ? 'word' : 'words'} #{words.join(', ')}"
40
+ "Match the #{match_words.size == 1 ? 'word' : 'words'} #{match_words.join(', ')}"
41
41
  end
42
42
 
43
43
  def data
44
- [title, words, workflow_action, workflow].to_json
44
+ [title, match_words, workflow_action, workflow_code].to_json
45
45
  end
46
46
 
47
47
  def expected_outcomes
@@ -53,7 +53,7 @@ module RulesEngine
53
53
  when 'stop_failure'
54
54
  [:outcome => RulesEngine::Rule::Outcome::STOP_FAILURE]
55
55
  when 'start_workflow'
56
- [:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :title => "Start Workflow : #{workflow}"]
56
+ [:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :title => "Start Workflow : #{workflow_code}"]
57
57
  else
58
58
  [:outcome => RulesEngine::Rule::Outcome::NEXT]
59
59
  end
@@ -66,26 +66,26 @@ module RulesEngine
66
66
 
67
67
  @title = param_hash[:<%=rule_name%>_title]
68
68
 
69
- @words = []
70
- return if param_hash[:<%=rule_name%>_words].nil?
71
- param_hash[:<%=rule_name%>_words].each do |key, values|
69
+ @match_words = []
70
+ return if param_hash[:<%=rule_name%>_match_words].nil?
71
+ param_hash[:<%=rule_name%>_match_words].each do |key, values|
72
72
  if values.is_a?(Hash)
73
73
  word_hash = values.symbolize_keys
74
- @words << word_hash[:word].downcase unless word_hash[:word].blank? || word_hash[:_delete] == '1'
74
+ @match_words << word_hash[:word].downcase unless word_hash[:word].blank? || word_hash[:_delete] == '1'
75
75
  end
76
76
  end
77
77
 
78
78
  @workflow_action = param_hash[:<%=rule_name%>_workflow_action] || 'continue'
79
- @workflow = param_hash[:<%=rule_name%>_workflow]
79
+ @workflow_code = param_hash[:<%=rule_name%>_workflow_code]
80
80
  end
81
81
 
82
82
  ##################################################################
83
83
  # validation and errors
84
84
  def valid?
85
85
  @errors = {}
86
- @errors[:<%=rule_name%>_words] = "At least one word must be defined" if words.nil? || words.empty?
87
86
  @errors[:<%=rule_name%>_title] = "Title required" if title.blank?
88
- @errors[:<%=rule_name%>_workflow] = "Workflow required" if workflow_action == 'start_workflow' && workflow.blank?
87
+ @errors[:<%=rule_name%>_match_words] = "At least one word must be defined" if match_words.nil? || match_words.empty?
88
+ @errors[:<%=rule_name%>_workflow_code] = "Workflow code required" if workflow_action == 'start_workflow' && workflow_code.blank?
89
89
  return @errors.empty?
90
90
  end
91
91
 
@@ -105,13 +105,13 @@ module RulesEngine
105
105
  # if a match is found procees to the expected outcome
106
106
  # it gets the data parameter :tweet
107
107
  # it sets the data parameter :match
108
- def process(process_id, data)
108
+ def process(process_id, plan, data)
109
109
  tweet = data[:tweet] || data["tweet"]
110
110
  if tweet.blank?
111
111
  return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
112
112
  end
113
113
 
114
- words.each do |word|
114
+ match_words.each do |word|
115
115
  if /\b#{word}\b/i =~ tweet
116
116
  RulesEngine::Process.auditor.audit(process_id, "Found #{word}", RulesEngine::Process::AUDIT_INFO)
117
117
  data[:tweet_match] = word
@@ -122,7 +122,7 @@ module RulesEngine
122
122
  when 'stop_failure'
123
123
  return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
124
124
  when 'start_workflow'
125
- return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, workflow)
125
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, workflow_code)
126
126
  else #'next'
127
127
  return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
128
128
  end