Class: ReWorkflow
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ReWorkflow
- Defined in:
- app/models/re_workflow.rb
Instance Method Summary collapse
- #before_destroy_workflow ⇒ Object
- #before_save_workflow ⇒ Object
- #changed! ⇒ Object
- #code=(new_code) ⇒ Object
- #has_plan?(re_plan) ⇒ Boolean
- #publish ⇒ Object
- #revert!(rule_data) ⇒ Object
- #workflow_error ⇒ Object
Instance Method Details
#before_destroy_workflow ⇒ Object
20 21 22 23 24 |
# File 'app/models/re_workflow.rb', line 20 def before_destroy_workflow re_plans.each do |re_plan| re_plan.changed! end end |
#before_save_workflow ⇒ Object
16 17 18 |
# File 'app/models/re_workflow.rb', line 16 def before_save_workflow self.changed! if changes.detect { |change| !ignore_attributes.include?(change[0])} end |
#changed! ⇒ Object
54 55 56 57 58 |
# File 'app/models/re_workflow.rb', line 54 def changed! re_plans.each do |re_plan| re_plan.changed! end end |
#code=(new_code) ⇒ Object
26 27 28 |
# File 'app/models/re_workflow.rb', line 26 def code=(new_code) self[:code] = new_code.strip.downcase.gsub(/[^a-zA-Z0-9]+/i, '_') if new_code && new_record? end |
#has_plan?(re_plan) ⇒ Boolean
60 61 62 |
# File 'app/models/re_workflow.rb', line 60 def has_plan? re_plan re_plans.include? re_plan end |
#publish ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/models/re_workflow.rb', line 30 def publish { "code" => code, "title" => title, "description" => description, "rules" => re_rules.map{ | re_rule | re_rule.publish } } end |
#revert!(rule_data) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/models/re_workflow.rb', line 38 def revert!(rule_data) self.code = rule_data["code"] self.title = rule_data["title"] self.description = rule_data["description"] self.re_rules = (rule_data["rules"] || []).map { |rule| ReRule.new.revert!(rule) } self end |
#workflow_error ⇒ Object
47 48 49 50 51 |
# File 'app/models/re_workflow.rb', line 47 def workflow_error return 'rules required' if re_rules.empty? return 'error within rules' if re_rules.any? { | re_rule | re_rule.rule_error } nil end |