rules_engine 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/VERSION +1 -1
  2. data/lib/rules_engine.rb +2 -2
  3. data/lib/rules_engine/discovery.rb +1 -1
  4. data/lib/rules_engine/process/runner.rb +3 -3
  5. data/lib/rules_engine/rule/definition.rb +85 -0
  6. data/lib/rules_engine/rule/outcome.rb +19 -0
  7. data/rails_generators/manifests/complex.rb +30 -0
  8. data/rails_generators/manifests/complex.yml +24 -0
  9. data/rails_generators/manifests/simple.rb +26 -0
  10. data/rails_generators/manifests/simple.yml +21 -0
  11. data/rails_generators/rules_engine_generator.rb +2 -2
  12. data/rails_generators/templates/app/models/re_rule.rb +4 -4
  13. data/rails_generators/templates/app/models/re_rule_expected_outcome.rb +1 -1
  14. data/rails_generators/templates/app/rules/complex.rb +133 -0
  15. data/rails_generators/templates/app/rules/simple.rb +83 -0
  16. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_edit.html.erb +0 -0
  17. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_help.html.erb +0 -0
  18. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_new.html.erb +0 -0
  19. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_script.html.erb +0 -0
  20. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_title.html.erb +0 -0
  21. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_word.html.erb +0 -0
  22. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_words.html.erb +0 -0
  23. data/rails_generators/templates/app/views/re_rule_definitions/{rule_complex → complex}/_workflow.html.erb +0 -0
  24. data/rails_generators/templates/app/views/re_rule_definitions/simple/_edit.html.erb +1 -0
  25. data/rails_generators/templates/app/views/re_rule_definitions/simple/_form.html.erb +16 -0
  26. data/rails_generators/templates/app/views/re_rule_definitions/simple/_help.html.erb +1 -0
  27. data/rails_generators/templates/app/views/re_rule_definitions/simple/_new.html.erb +1 -0
  28. data/rails_generators/templates/doc/README.rules_engine +1 -1
  29. data/rails_generators/templates/spec/lib/rules/{rule_complex_spec.rb → complex_spec.rb} +30 -30
  30. data/rails_generators/templates/spec/lib/rules/simple_spec.rb +161 -0
  31. data/rails_generators/templates/spec/models/re_rule_expected_outcome_spec.rb +3 -3
  32. data/rails_generators/templates/spec/models/re_rule_spec.rb +11 -11
  33. data/spec/railsenv/app/rules/mock_rule.rb +9 -10
  34. data/spec/railsenv/log/debug.log +1356 -0
  35. data/spec/railsenv/log/test.log +78 -0
  36. data/spec/rules_engine/discovery_spec.rb +17 -7
  37. data/spec/rules_engine/process/runner_spec.rb +8 -8
  38. data/spec/rules_engine/{rule_spec.rb → rule/definition_spec.rb} +17 -17
  39. metadata +27 -27
  40. data/lib/rules_engine/rule.rb +0 -84
  41. data/lib/rules_engine/rule_outcome.rb +0 -17
  42. data/rails_generators/manifests/rule_complex.rb +0 -30
  43. data/rails_generators/manifests/rule_complex.yml +0 -24
  44. data/rails_generators/manifests/rule_simple.rb +0 -26
  45. data/rails_generators/manifests/rule_simple.yml +0 -21
  46. data/rails_generators/templates/app/rules/rule_complex.rb +0 -130
  47. data/rails_generators/templates/app/rules/rule_simple.rb +0 -79
  48. data/rails_generators/templates/app/views/re_rule_definitions/rule_simple/_edit.html.erb +0 -1
  49. data/rails_generators/templates/app/views/re_rule_definitions/rule_simple/_form.html.erb +0 -16
  50. data/rails_generators/templates/app/views/re_rule_definitions/rule_simple/_help.html.erb +0 -1
  51. data/rails_generators/templates/app/views/re_rule_definitions/rule_simple/_new.html.erb +0 -1
  52. data/rails_generators/templates/spec/lib/rules/rule_simple_spec.rb +0 -161
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/lib/rules_engine.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/rules_engine/discovery")
2
- require File.expand_path(File.dirname(__FILE__) + "/rules_engine/rule")
3
- require File.expand_path(File.dirname(__FILE__) + "/rules_engine/rule_outcome")
2
+ require File.expand_path(File.dirname(__FILE__) + "/rules_engine/rule/definition")
3
+ require File.expand_path(File.dirname(__FILE__) + "/rules_engine/rule/outcome")
4
4
 
5
5
  require File.expand_path(File.dirname(__FILE__) + "/rules_engine/cache")
6
6
  require File.expand_path(File.dirname(__FILE__) + "/rules_engine/publish/publisher")
@@ -23,7 +23,7 @@ module RulesEngine
23
23
  Dir.glob("#{rules_path}/**/*.rb").each do |rule|
24
24
  Kernel.load rule
25
25
 
26
- rule_class = Kernel.const_get(File.basename(rule, '.rb').classify)
26
+ rule_class = Rule.const_get(File.basename(rule, '.rb').classify)
27
27
  @rule_classes << rule_class
28
28
 
29
29
  group = rule_class.options[:group]
@@ -98,19 +98,19 @@ module RulesEngine
98
98
  rule_outcome = rule.process(process_id, data)
99
99
  RulesEngine::Process.auditor.audit(process_id, "Rule : #{rule.title} : finished")
100
100
 
101
- if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::RuleOutcome::OUTCOME_STOP_SUCCESS
101
+ if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_SUCCESS
102
102
  RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : stop success", RulesEngine::Process::AUDIT_SUCCESS)
103
103
  done = true
104
104
  break
105
105
  end
106
106
 
107
- if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::RuleOutcome::OUTCOME_STOP_FAILURE
107
+ if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE
108
108
  RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : stop failure", RulesEngine::Process::AUDIT_FAILURE)
109
109
  error = done = true
110
110
  break
111
111
  end
112
112
 
113
- if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::RuleOutcome::OUTCOME_START_WORKFLOW
113
+ if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::START_WORKFLOW
114
114
  RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : start next workflow - #{rule_outcome.workflow_code}", RulesEngine::Process::AUDIT_INFO)
115
115
  next_workflow = rule_outcome.workflow_code
116
116
  break
@@ -0,0 +1,85 @@
1
+ module RulesEngine
2
+ module Rule
3
+ class Definition
4
+ def self.inherited(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def rule_class_name
10
+ self.name.classify
11
+ end
12
+ end
13
+
14
+ ##################################################################
15
+ # class options
16
+ class_inheritable_accessor :options
17
+ @@options = {
18
+ # :group => "The group the rule belongs to",
19
+ # :display_name => "name to use on forms and views",
20
+ # :help_partial => "the help html.erb template",
21
+ # :new_partial => "the new html.erb template",
22
+ # :edit_partial => "the edit html.erb template"
23
+ }
24
+
25
+ ##################################################################
26
+ # set the rule data
27
+ def data= data
28
+ end
29
+
30
+ ##################################################################
31
+ # get the rule attributes
32
+ def title
33
+ return nil
34
+ end
35
+
36
+ def summary
37
+ return nil
38
+ end
39
+
40
+ def data
41
+ return nil
42
+ end
43
+
44
+ def expected_outcomes
45
+ [:outcome => RulesEngine::Rule::Outcome::NEXT]
46
+ end
47
+
48
+ ##################################################################
49
+ # set the rule attributes
50
+ def attributes=(params)
51
+ end
52
+
53
+ ##################################################################
54
+ # validation and errors
55
+ def valid?
56
+ true
57
+ end
58
+
59
+ def errors
60
+ @errors ||= {}
61
+ return @errors
62
+ end
63
+
64
+ ##################################################################
65
+ # callbacks when the rule is added and removed from a workflow
66
+ def after_add_to_workflow(workflow_code)
67
+ end
68
+
69
+ def before_remove_from_workflow(workflow_code)
70
+ end
71
+
72
+ ##################################################################
73
+ # execute the rule
74
+ # return an RulesEngine::Rule::Outcome object to define what to do next
75
+ # if nil to continue to the next rule
76
+ def process(process_id, data)
77
+ # process.audit("process #{title}", RulesEngine::Process::AUDIT_INFO)
78
+ # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
79
+ # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
80
+ # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, 'next_workflow')
81
+ RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,19 @@
1
+ module RulesEngine
2
+ module Rule
3
+ class Outcome
4
+
5
+ def initialize(outcome, workflow_code = nil)
6
+ @outcome = outcome
7
+ @workflow_code = workflow_code
8
+ end
9
+
10
+ NEXT = 0
11
+ STOP_SUCCESS = 1
12
+ STOP_FAILURE = 2
13
+ START_WORKFLOW = 3
14
+
15
+ attr_accessor :outcome
16
+ attr_accessor :workflow_code
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ class ComplexManifest
2
+ def self.populate_record(m, rule_name ,rule_class)
3
+
4
+ %W(
5
+ app/rules
6
+ app/views/re_rule_definitions/#{rule_name}
7
+ lib/tasks
8
+ spec/lib/rules
9
+ ).each do |dirname|
10
+ m.directory dirname
11
+ end
12
+
13
+ %W(
14
+ ).each do |filename|
15
+ m.file filename, filename
16
+ end
17
+
18
+ m.template "app/rules/complex.rb", "app/rules/#{rule_name}.rb"
19
+ m.template "app/views/re_rule_definitions/complex/_edit.html.erb", "app/views/re_rule_definitions/#{rule_name}/_edit.html.erb"
20
+ m.template "app/views/re_rule_definitions/complex/_help.html.erb", "app/views/re_rule_definitions/#{rule_name}/_help.html.erb"
21
+ m.template "app/views/re_rule_definitions/complex/_new.html.erb", "app/views/re_rule_definitions/#{rule_name}/_new.html.erb"
22
+ m.template "app/views/re_rule_definitions/complex/_script.html.erb", "app/views/re_rule_definitions/#{rule_name}/_script.html.erb"
23
+ m.template "app/views/re_rule_definitions/complex/_title.html.erb", "app/views/re_rule_definitions/#{rule_name}/_title.html.erb"
24
+ m.template "app/views/re_rule_definitions/complex/_word.html.erb", "app/views/re_rule_definitions/#{rule_name}/_word.html.erb"
25
+ m.template "app/views/re_rule_definitions/complex/_words.html.erb", "app/views/re_rule_definitions/#{rule_name}/_words.html.erb"
26
+ m.template "app/views/re_rule_definitions/complex/_workflow.html.erb", "app/views/re_rule_definitions/#{rule_name}/_workflow.html.erb"
27
+ m.template "spec/lib/rules/complex_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
28
+
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ directories :
2
+ - app/rules
3
+ - spec/lib/rules
4
+ - lib/tasks
5
+
6
+ templates :
7
+ replacements :
8
+ - complex : rule_name
9
+ - Complex : rule_class
10
+
11
+ directories :
12
+ - app/views/re_rule_definitions/complex
13
+
14
+ files :
15
+ - app/rules/complex.rb
16
+ - app/views/re_rule_definitions/complex/_edit.html.erb
17
+ - app/views/re_rule_definitions/complex/_help.html.erb
18
+ - app/views/re_rule_definitions/complex/_workflow.html.erb
19
+ - app/views/re_rule_definitions/complex/_script.html.erb
20
+ - app/views/re_rule_definitions/complex/_title.html.erb
21
+ - app/views/re_rule_definitions/complex/_new.html.erb
22
+ - app/views/re_rule_definitions/complex/_word.html.erb
23
+ - app/views/re_rule_definitions/complex/_words.html.erb
24
+ - spec/lib/rules/complex_spec.rb
@@ -0,0 +1,26 @@
1
+ class SimpleManifest
2
+ def self.populate_record(m, rule_name ,rule_class)
3
+
4
+ %W(
5
+ app/rules
6
+ app/views/re_rule_definitions/#{rule_name}
7
+ lib/tasks
8
+ spec/lib/rules
9
+ ).each do |dirname|
10
+ m.directory dirname
11
+ end
12
+
13
+ %W(
14
+ ).each do |filename|
15
+ m.file filename, filename
16
+ end
17
+
18
+ m.template "app/rules/simple.rb", "app/rules/#{rule_name}.rb"
19
+ m.template "app/views/re_rule_definitions/simple/_edit.html.erb", "app/views/re_rule_definitions/#{rule_name}/_edit.html.erb"
20
+ m.template "app/views/re_rule_definitions/simple/_form.html.erb", "app/views/re_rule_definitions/#{rule_name}/_form.html.erb"
21
+ m.template "app/views/re_rule_definitions/simple/_help.html.erb", "app/views/re_rule_definitions/#{rule_name}/_help.html.erb"
22
+ m.template "app/views/re_rule_definitions/simple/_new.html.erb", "app/views/re_rule_definitions/#{rule_name}/_new.html.erb"
23
+ m.template "spec/lib/rules/simple_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
24
+
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ directories :
2
+ - app/rules
3
+ - spec/lib/rules
4
+ - lib/tasks
5
+
6
+ templates :
7
+ replacements :
8
+ - simple : rule_name
9
+ - RuleSimple : rule_class
10
+
11
+ directories :
12
+ - app/views/re_rule_definitions/simple
13
+
14
+ files :
15
+ - app/rules/simple.rb
16
+ - app/views/re_rule_definitions/simple/_edit.html.erb
17
+ - app/views/re_rule_definitions/simple/_help.html.erb
18
+ - app/views/re_rule_definitions/simple/_new.html.erb
19
+ - app/views/re_rule_definitions/simple/_form.html.erb
20
+ - spec/lib/rules/simple_spec.rb
21
+
@@ -21,8 +21,8 @@ class RulesEngineGenerator < Rails::Generator::Base
21
21
  puts ''
22
22
  end
23
23
  if @rule_name.nil?
24
- puts 'run >script/generate rules_engine rule_simple [rule name]'
25
- puts 'run >script/generate rules_engine rule_complex [rule name]'
24
+ puts 'run >script/generate rules_engine simple [rule name]'
25
+ puts 'run >script/generate rules_engine complex [rule name]'
26
26
  puts ''
27
27
  puts "or install the rules_engine_templates gem to see other templates"
28
28
  puts ''
@@ -89,19 +89,19 @@ class ReRule < ActiveRecord::Base
89
89
  end
90
90
 
91
91
  def re_rule_expected_outcome_next
92
- re_rule_expected_outcomes.detect{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::RuleOutcome::OUTCOME_NEXT }
92
+ re_rule_expected_outcomes.detect{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::Rule::Outcome::NEXT }
93
93
  end
94
94
 
95
95
  def re_rule_expected_outcome_success
96
- re_rule_expected_outcomes.detect{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::RuleOutcome::OUTCOME_STOP_SUCCESS }
96
+ re_rule_expected_outcomes.detect{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::Rule::Outcome::STOP_SUCCESS }
97
97
  end
98
98
 
99
99
  def re_rule_expected_outcome_failure
100
- re_rule_expected_outcomes.detect{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::RuleOutcome::OUTCOME_STOP_FAILURE }
100
+ re_rule_expected_outcomes.detect{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE }
101
101
  end
102
102
 
103
103
  def re_rule_expected_outcomes_start_workflow
104
- re_rule_expected_outcomes.select{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::RuleOutcome::OUTCOME_START_WORKFLOW }
104
+ re_rule_expected_outcomes.select{ |re_rule_expected_outcome| re_rule_expected_outcome.outcome == RulesEngine::Rule::Outcome::START_WORKFLOW }
105
105
  end
106
106
 
107
107
  protected
@@ -5,7 +5,7 @@ class ReRuleExpectedOutcome < ActiveRecord::Base
5
5
  validates_presence_of :outcome
6
6
 
7
7
  def validate
8
- if outcome == RulesEngine::RuleOutcome::OUTCOME_START_WORKFLOW && workflow_code.blank?
8
+ if outcome == RulesEngine::Rule::Outcome::START_WORKFLOW && workflow_code.blank?
9
9
  errors.add(:workflow_code, "workflow code required")
10
10
  end
11
11
  end
@@ -0,0 +1,133 @@
1
+ module RulesEngine
2
+ module Rule
3
+ class <%=rule_class%> < RulesEngine::Rule::Definition
4
+
5
+ attr_reader :words
6
+ attr_reader :workflow_action
7
+ attr_reader :workflow
8
+
9
+ ##################################################################
10
+ # class options
11
+ self.options =
12
+ {
13
+ :group => 'General',
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'
18
+ }
19
+
20
+ ##################################################################
21
+ # set the rule data
22
+ def data= data
23
+ if data.nil?
24
+ @title = nil
25
+ @words = nil
26
+ @workflow_action = 'continue'
27
+ @workflow = nil
28
+ else
29
+ @title, @words, @workflow_action, @workflow = ActiveSupport::JSON.decode(data)
30
+ end
31
+ end
32
+
33
+ ##################################################################
34
+ # get the rule attributes
35
+ def title
36
+ @title
37
+ end
38
+
39
+ def summary
40
+ "Match the #{words.size == 1 ? 'word' : 'words'} #{words.join(', ')}"
41
+ end
42
+
43
+ def data
44
+ [title, words, workflow_action, workflow].to_json
45
+ end
46
+
47
+ def expected_outcomes
48
+ case workflow_action
49
+ when 'next'
50
+ [:outcome => RulesEngine::Rule::Outcome::NEXT]
51
+ when 'stop_success'
52
+ [:outcome => RulesEngine::Rule::Outcome::STOP_SUCCESS]
53
+ when 'stop_failure'
54
+ [:outcome => RulesEngine::Rule::Outcome::STOP_FAILURE]
55
+ when 'start_workflow'
56
+ [:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :workflow_code => workflow]
57
+ else
58
+ [:outcome => RulesEngine::Rule::Outcome::NEXT]
59
+ end
60
+ end
61
+
62
+ ##################################################################
63
+ # set the rule attributes
64
+ def attributes=(params)
65
+ param_hash = params.symbolize_keys
66
+
67
+ @title = param_hash[:<%=rule_name%>_title]
68
+
69
+ @words = []
70
+ return if param_hash[:<%=rule_name%>_words].nil?
71
+ param_hash[:<%=rule_name%>_words].each do |key, values|
72
+ if values.is_a?(Hash)
73
+ word_hash = values.symbolize_keys
74
+ @words << word_hash[:word].downcase unless word_hash[:word].blank? || word_hash[:_delete] == '1'
75
+ end
76
+ end
77
+
78
+ @workflow_action = param_hash[:<%=rule_name%>_workflow_action] || 'continue'
79
+ @workflow = param_hash[:<%=rule_name%>_workflow] || ''
80
+ end
81
+
82
+ ##################################################################
83
+ # validation and errors
84
+ def valid?
85
+ @errors = {}
86
+ @errors[:<%=rule_name%>_words] = "At least one word must be defined" if words.nil? || words.empty?
87
+ @errors[:<%=rule_name%>_title] = "Title required" if title.blank?
88
+ @errors[:<%=rule_name%>_workflow] = "Workflow required" if workflow_action == 'start_workflow' && workflow.blank?
89
+ return @errors.empty?
90
+ end
91
+
92
+ ##################################################################
93
+ # callbacks when the rule is added and removed from a workflow
94
+ def after_add_to_workflow(workflow_code)
95
+ end
96
+
97
+ def before_remove_from_workflow(workflow_code)
98
+ end
99
+
100
+ ##################################################################
101
+ # execute the rule
102
+ # if a match is found procees to the expected outcome
103
+ # it gets the data parameter :tweet
104
+ # it sets the data parameter :match
105
+ def process(process_id, data)
106
+ tweet = data[:tweet] || data["tweet"]
107
+ if tweet.blank?
108
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
109
+ end
110
+
111
+ words.each do |word|
112
+ if /#{word}/i =~ tweet
113
+ RulesEngine::Process.auditor.audit(process_id, "#{title} Found #{word}", RulesEngine::Process::AUDIT_INFO)
114
+ data[:match] = word
115
+
116
+ case workflow_action
117
+ when 'stop_success'
118
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
119
+ when 'stop_failure'
120
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
121
+ when 'start_workflow'
122
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, workflow)
123
+ else #'next'
124
+ return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
125
+ end
126
+ end
127
+ end
128
+
129
+ RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,83 @@
1
+ module RulesEngine
2
+ module Rule
3
+ class Simple < RulesEngine::Rule::Definition
4
+
5
+ attr_reader :description
6
+ ##################################################################
7
+ # class options
8
+ self.options =
9
+ {
10
+ :group => 'General',
11
+ :display_name => 'Simple',
12
+ :help_partial => '/re_rule_definitions/rule_<%=rule_name%>/help',
13
+ :new_partial => '/re_rule_definitions/rule_<%=rule_name%>/new',
14
+ :edit_partial => '/re_rule_definitions/rule_<%=rule_name%>/edit'
15
+ }
16
+
17
+ ##################################################################
18
+ # set the rule data
19
+ def data= data
20
+ if data.nil?
21
+ @title = nil
22
+ @description = nil
23
+ else
24
+ @title, @description = ActiveSupport::JSON.decode(data)
25
+ end
26
+ end
27
+
28
+ ##################################################################
29
+ # get the rule attributes
30
+ def title
31
+ @title
32
+ end
33
+
34
+ def summary
35
+ description || "Does Nothing"
36
+ end
37
+
38
+ def data
39
+ [title, description].to_json
40
+ end
41
+
42
+ def expected_outcomes
43
+ [:outcome => RulesEngine::Rule::Outcome::NEXT]
44
+ end
45
+
46
+ ##################################################################
47
+ # set the rule attributes
48
+ def attributes=(params)
49
+ param_hash = params.symbolize_keys
50
+
51
+ @title = param_hash[:rule_<%=rule_name%>_title]
52
+ @description = param_hash[:rule_<%=rule_name%>_description]
53
+ end
54
+
55
+ ##################################################################
56
+ # validation and errors
57
+ def valid?
58
+ @errors = {}
59
+ @errors[:rule_<%=rule_name%>_title] = "Title required" if title.blank?
60
+ return @errors.empty?
61
+ end
62
+
63
+ ##################################################################
64
+ # callbacks when the rule is added and removed from a workflow
65
+ def after_add_to_workflow(workflow_code)
66
+ end
67
+
68
+ def before_remove_from_workflow(workflow_code)
69
+ end
70
+
71
+ ##################################################################
72
+ # execute the rule
73
+ # this rule does nothing
74
+ def process(process_id, data)
75
+ RulesEngine::Process.auditor.audit(process_id, "Inside Rule #{title}", RulesEngine::Process::AUDIT_INFO)
76
+ # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
77
+ # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
78
+ # RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, 'next_workflow')
79
+ RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
80
+ end
81
+ end
82
+ end
83
+ end