module RulesEngine module Rule class <%=rule_class%> < RulesEngine::Rule::Definition attr_reader :workflow_code ################################################################## # class options self.options = { :group => 'Workflow', :display_name => 'Workflow Start', :help_partial => '/re_rules/<%=rule_name%>/help', :new_partial => '/re_rules/<%=rule_name%>/new', :edit_partial => '/re_rules/<%=rule_name%>/edit' } ################################################################## # set the rule data def data= data if data.nil? @title = nil @workflow_code = nil else @title, @workflow_code = ActiveSupport::JSON.decode(data) end end ################################################################## # get the rule attributes def title @title end def summary "Start the workflow : #{workflow_code}" end def data [title, workflow_code].to_json end def expected_outcomes [:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :title => "Start workflow : #{workflow_code}"] end ################################################################## # set the rule attributes def attributes=(params) param_hash = params.symbolize_keys @title = param_hash[:<%=rule_name%>_title] @workflow_code = param_hash[:<%=rule_name%>_workflow_code] end ################################################################## # validation and errors def valid? @errors = {} @errors[:<%=rule_name%>_title] = "Title required" if title.blank? @errors[:<%=rule_name%>_workflow_code] = "Workflow required" if workflow_code.blank? return @errors.empty? end ################################################################## # callbacks when the rule is added and removed from a workflow def before_create() end def before_update() end def before_destroy() end ################################################################## # execute the rule # start the workflow def process(process_id, plan, data) return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, workflow_code) end end end end