Sha256: 81a6dad7112812e397a3643bc8bc670f637559b06a3f801a6b574953f00094fd

Contents?: true

Size: 1.5 KB

Versions: 24

Compression:

Stored size: 1.5 KB

Contents

rad.remote

class RemoteCaller < Rad::Conveyors::Processor
  # TODO2 :remote isn't registered with rad[
  inject remote: :remote
  
  def initialize next_processor, result_variable = 'content'
    super(next_processor)
    @result_variable = result_variable
  end
  
  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.message}.to_json

      logger.error e
      logger.info "\n"
    end
  end
  
  private
    def ensure_correct_result! result
      unless result.rson?
        raise "You can't use object of type '#{result.class}' as Remote's return value!"
      end
    end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rad_core-0.2.6 lib/rad/remote/processors/remote_caller.rb
rad_core-0.2.5 lib/rad/remote/processors/remote_caller.rb
rad_core-0.2.4 lib/rad/remote/processors/remote_caller.rb
rad_core-0.2.3 lib/rad/remote/processors/remote_caller.rb
rad_core-0.2.2 lib/rad/remote/processors/remote_caller.rb
rad_core-0.2.1 lib/rad/remote/processors/remote_caller.rb
rad_core-0.2.0 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.30 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.29 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.28 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.27 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.26 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.25 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.24 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.23 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.22 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.21 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.20 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.19 lib/rad/remote/processors/remote_caller.rb
rad_core-0.0.18 lib/rad/remote/processors/remote_caller.rb