liveh2o / active_remote

Active Remote provides Active Record-like object-relational mapping over RPC. It's Active Record for your platform.
MIT License
63 stars 23 forks source link

Make rdp_adapter pluggable #38

Open mattnichols opened 8 years ago

mattnichols commented 8 years ago

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

liveh2o commented 8 years ago

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.