Class: ErpRules::Search::SearchBase
- Inherits:
-
Object
- Object
- ErpRules::Search::SearchBase
- Defined in:
- lib/erp_rules/search/search_base.rb
Instance Method Summary collapse
- #create_search_execution_context(facts, options = {}) ⇒ Object
-
#do_search(ctx) ⇒ Object
This is the vertical search method that will need to be implemented in the sub-class.
-
#generate_rules(ctx) ⇒ Object
This must return an object (class, hash, whatever) that is used by the rules engine as a sort of rule book.
-
#pre_process_facts(facts) ⇒ Object
Perform any processing the facts passed by a search controller.
- #process_search_facts(facts, search_rules_klass, context_builder_klass = ErpRules::RulesEngine::ContextBuilder) ⇒ Object
- #search(facts) ⇒ Object
Instance Method Details
#create_search_execution_context(facts, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/erp_rules/search/search_base.rb', line 48 def create_search_execution_context(facts, ={}) [:persistant] = false if [:persistant].nil? # Get execution context context_builder = [:context_builder_klass].new(facts) execution_context = context_builder.build_execution_context() # If persistant, save to database if [:persistant] context_builder.persist_context(self.class.to_s, facts[:search_params][:search_type]) end return execution_context end |
#do_search(ctx) ⇒ Object
This is the vertical search method that will need to be implemented in the sub-class
11 12 13 |
# File 'lib/erp_rules/search/search_base.rb', line 11 def do_search ctx raise "do_search needs to be implemented in the subclass" end |
#generate_rules(ctx) ⇒ Object
This must return an object (class, hash, whatever) that is used by the rules engine as a sort of rule book.
22 23 24 |
# File 'lib/erp_rules/search/search_base.rb', line 22 def generate_rules ctx raise "generate_rules must be implemented in the subclass" end |
#pre_process_facts(facts) ⇒ Object
Perform any processing the facts passed by a search controller
16 17 18 |
# File 'lib/erp_rules/search/search_base.rb', line 16 def pre_process_facts facts raise "pre_process_facts needs to be implemented in the subclass" end |
#process_search_facts(facts, search_rules_klass, context_builder_klass = ErpRules::RulesEngine::ContextBuilder) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/erp_rules/search/search_base.rb', line 26 def process_search_facts(facts, search_rules_klass, context_builder_klass=ErpRules::RulesEngine::ContextBuilder) # breaking out Orange Lake search logic into a subclass # this creates a requirement that this class be extended with a subclass containing pre_process_facts method facts = pre_process_facts(facts) # build the execution context for the rules engine search_execution_context = create_search_execution_context(facts, {:persistant => Constants::SEARCH_TXN_PERSISTANT, :context_builder_klass => context_builder_klass}) ruleset = generate_rules ctx #execute the reservation_search rules and get back some search filtering criteria filters = ErpRules::RulesEngine::RulesFacade.new.invoke(ruleset, search_execution_context, search_rules_klass) # breaking out Orange Lake search logic into a subclass # this creates a requirement that this class be extended with a subclass containing vertical_search method res_search_results, = do_search(facts, filters) return res_search_results, end |
#search(facts) ⇒ Object
5 6 7 |
# File 'lib/erp_rules/search/search_base.rb', line 5 def search facts return process_search_facts(facts) end |