Class: Rhoconnect::Handler::Search::Engine
- Inherits:
-
Object
- Object
- Rhoconnect::Handler::Search::Engine
- Includes:
- Helpers::AuthMethod, Helpers::Binding
- Defined in:
- lib/rhoconnect/handler/search/engine.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#model ⇒ Object
Returns the value of attribute model.
-
#params ⇒ Object
Returns the value of attribute params.
-
#route_handler ⇒ Object
Returns the value of attribute route_handler.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #do_search ⇒ Object
-
#initialize(model, client, route_handler, params = {}) ⇒ Engine
constructor
A new instance of Engine.
- #run_search ⇒ Object
Methods included from Helpers::Binding
Methods included from Helpers::AuthMethod
Constructor Details
#initialize(model, client, route_handler, params = {}) ⇒ Engine
Returns a new instance of Engine.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 10 def initialize(model, client, route_handler, params = {}) raise ArgumentError.new(UNKNOWN_CLIENT) unless client raise ArgumentError.new(UNKNOWN_SOURCE) unless (model and model.source) raise ArgumentError.new('Invalid app for source') unless model.source.app raise ArgumentError.new('Invalid sync handler') unless route_handler @client = client @source = model.source @model = model # if handler is not bound - bind it to self # normally it should be bound to a Controller's instance @route_handler = bind_handler(:search_handler_method, route_handler) @params = params end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 5 def client @client end |
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 5 def model @model end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 5 def params @params end |
#route_handler ⇒ Object
Returns the value of attribute route_handler.
5 6 7 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 5 def route_handler @route_handler end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 5 def source @source end |
Instance Method Details
#do_search ⇒ Object
25 26 27 28 29 30 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 25 def do_search return if auth_method('login',client.id) == false res = run_search auth_method('logoff',client.id) res end |
#run_search ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rhoconnect/handler/search/engine.rb', line 32 def run_search errordoc = nil docobj = nil result = nil begin errordoc = :search_errors docobj = client client.compute_token(:search_token) result = @route_handler.call client.put_data(:search,result) unless @source.is_pass_through? # operation,sync succeeded, remove errors docobj.lock(errordoc) do docobj.flush_data(errordoc) end rescue Exception => e # store sync,operation exceptions to be sent to all clients for this source/user log "Model raised search exception: #{e}" log e.backtrace.join("\n") docobj.lock(errordoc) do docobj.put_data(errordoc,{"search-error"=>{'message'=>e.}},true) end end # pass through expects result hash @source.is_pass_through? ? result : true end |