Skip to content

Make rdp_adapter pluggable #38

@mattnichols

Description

@mattnichols

I propose adding the following to the README and implementing the adapter described:

RPC Adapter

An RPC Adapter is responsible for gathering the attributes from your model and marshalling them to the RPC call. Marshalling behaviors can be injected or modified at this point. The default RPC adapter is ::ActiveRemote::RPCAdapters::ProtobufAdapter.

You can, of course override it if need be:

  # If you have a custom rpc adapter to use globally:
  ::ActiveRemote::RPC.default_adapter = ::MyCustom::RPCAdapter

  # If you have a custom rpc adapter for an individual class:
  class Product < ActiveRemote::Base
    rpc_adapter ::MyCustom::RPCAdapter
  end

  # If you have a custom rpc adapter that has special setup needs:
  class Product < ActiveRemote::Base
    rpc_adapter :build_custom_rpc_adapter

    private

    def build_custom_rpc_adapter(model)
      ::MyCustom::RPCAdapter.new(@rpc_settings)
    end
  end

  # Or, with a block
  class Product < ActiveRemote::Base
    rpc_adapter do |model|
      ::MyCustom::RPCAdapter.new(model.rpc_settings)
    end
  end

@liveh2o @brianstien

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions