Class: RemoteCaller
- Inherits:
-
Rad::Conveyors::Processor
- Object
- Rad::Conveyors::Processor
- RemoteCaller
- Defined in:
- lib/rad/remote/processors/remote_caller.rb
Instance Attribute Summary
Attributes inherited from Rad::Conveyors::Processor
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(next_processor, result_variable = 'content') ⇒ RemoteCaller
constructor
A new instance of RemoteCaller.
Methods inherited from Rad::Conveyors::Processor
Constructor Details
#initialize(next_processor, result_variable = 'content') ⇒ RemoteCaller
Returns a new instance of RemoteCaller.
7 8 9 10 |
# File 'lib/rad/remote/processors/remote_caller.rb', line 7 def initialize next_processor, result_variable = 'content' super(next_processor) @result_variable = result_variable end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rad/remote/processors/remote_caller.rb', line 12 def call return next_processor.call unless workspace.class? # prepare klass = workspace.class raise "The remote class #{klass} must be a Rad::Remote::RemoteController!" unless klass.is? Rad::Remote::RemoteController workspace.remote_object = klass.new method = workspace.method_name # call begin result = workspace.remote_object.run_callbacks :action, method: method do workspace.remote_object.send method end ensure_correct_result! result workspace.remote_result = result next_processor.call # write JSON as a result if format is JSON and no one else filled it if workspace[@result_variable].blank? workspace[@result_variable] = workspace.remote_result.to_json end rescue StandardError => e raise e if !workspace.params.format == 'json' or rad.test? workspace[@result_variable] = {error: e.}.to_json logger.error e logger.info "\n" end end |