Class: Rhoconnect::Handler::Changes::Engine
- Inherits:
-
Object
- Object
- Rhoconnect::Handler::Changes::Engine
- Includes:
- Helpers::AuthMethod, Helpers::Binding, Helpers::SourceJob
- Defined in:
- lib/rhoconnect/handler/changes/engine.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#operations ⇒ Object
Returns the value of attribute operations.
-
#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
-
#create ⇒ Object
CUD Operations.
- #delete ⇒ Object
- #do_cud ⇒ Object
-
#do_pass_through_cud ⇒ Object
Pass through CUD to adapter, no data stored.
-
#initialize(operations, model, route_handler, params = {}) ⇒ Engine
constructor
A new instance of Engine.
- #run_cud ⇒ Object
- #update ⇒ Object
Methods included from Helpers::AuthMethod
Methods included from Helpers::Binding
Methods included from Helpers::SourceJob
Constructor Details
#initialize(operations, model, route_handler, params = {}) ⇒ Engine
Returns a new instance of Engine.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 11 def initialize(operations, model, route_handler, params = {}) 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 CUD handler') unless route_handler @source = model.source # if handler is not bound - bind it to self # normally it should be bound to a Controller's instance @route_handler = bind_handler(:cud_handler_method, route_handler) @params = params @model = model @operations = operations end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 5 def model @model end |
#operations ⇒ Object
Returns the value of attribute operations.
5 6 7 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 5 def operations @operations end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/rhoconnect/handler/changes/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/changes/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/changes/engine.rb', line 5 def source @source end |
Instance Method Details
#create ⇒ Object
CUD Operations
74 75 76 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 74 def create _measure_and_process_cud('create') end |
#delete ⇒ Object
82 83 84 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 82 def delete _measure_and_process_cud('delete') end |
#do_cud ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 25 def do_cud if source.cud_queue or source.queue async(:cud,source.cud_queue || source.queue) else run_cud end end |
#do_pass_through_cud ⇒ Object
Pass through CUD to adapter, no data stored
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 34 def do_pass_through_cud return if auth_method('login') == false res,processed_objects = {},[] begin operations.each do |op| objects = params[op] params[:operation] = op if objects objects.each do |key,value| case op when 'create' params[:create_object] = value @route_handler.call when 'update' value['id'] = key params[:update_object] = value @route_handler.call when 'delete' value['id'] = key params[:delete_object] = value @route_handler.call end processed_objects << key end if objects end rescue Exception => e log "Error in pass through method: #{e.}" res['error'] = {'message' => e. } end auth_method('logoff') res['processed'] = processed_objects res.to_json end |
#run_cud ⇒ Object
67 68 69 70 71 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 67 def run_cud operations.each do |op| send op.to_sym end end |
#update ⇒ Object
78 79 80 |
# File 'lib/rhoconnect/handler/changes/engine.rb', line 78 def update _measure_and_process_cud('update') end |