active_remote
active_remote copied to clipboard
Make rdp_adapter pluggable
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
Making the RPC adapter pluggable has been the intention (in fact, it's the reason the RPC adapter class exists), but since we only have a need for the Protobuf adapter , the rest of the work to support it has not been completed. I'd :heart: a PR.