Class: ReRule
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ReRule
- Defined in:
- app/models/re_rule.rb
Instance Method Summary collapse
- #before_destroy_rule ⇒ Object
- #before_save_rule ⇒ Object
- #publish ⇒ Object
- #revert!(rule_data) ⇒ Object
- #rule ⇒ Object
- #rule_attributes=(params) ⇒ Object
- #rule_error ⇒ Object
- #validate_rule ⇒ Object
Instance Method Details
#before_destroy_rule ⇒ Object
30 31 32 |
# File 'app/models/re_rule.rb', line 30 def before_destroy_rule rule.before_destroy() unless rule.nil? end |
#before_save_rule ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/re_rule.rb', line 14 def before_save_rule return if rule.nil? if self.new_record? rule.before_create() else rule.before_update() end self.title = rule.title self.summary = rule.summary self.data = rule.data re_workflow.changed! if changes.detect { |change| !ignore_attributes.include?(change[0])} end |
#publish ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/models/re_rule.rb', line 44 def publish { "rule_class_name" => rule_class_name, "title" => title, "summary" => summary, "data" => data } end |
#revert!(rule_data) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'app/models/re_rule.rb', line 52 def revert!(rule_data) self.rule_class_name = rule_data["rule_class_name"] self.title = rule_data["title"] self.summary = rule_data["summary"] self.data = rule_data["data"] self end |
#rule ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/models/re_rule.rb', line 61 def rule return @rule unless @rule.nil? rule_class = RulesEngine::Discovery.rule_class(self.rule_class_name) return nil if rule_class.nil? @rule = rule_class.new @rule.data = self.data @rule end |
#rule_attributes=(params) ⇒ Object
70 71 72 73 |
# File 'app/models/re_rule.rb', line 70 def rule_attributes=params raise 'rule class not found' if rule.nil? rule.attributes = params end |
#rule_error ⇒ Object
75 76 77 78 79 80 |
# File 'app/models/re_rule.rb', line 75 def rule_error return "class #{rule_class_name} missing" if rule.nil? return "#{rule.errors.values.join(', ')}" unless rule.valid? nil end |
#validate_rule ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/models/re_rule.rb', line 34 def validate_rule if self.rule.nil? errors.add("rule_class", "not found") elsif !self.rule.valid? errors.add(self.rule_class_name, "not valid") else true end end |