module RemoteRecord::DSL

A DSL that's helpful for configuring remote references. To configure a remote reference, `include RemoteRecord`, then call `remote_record` to configure the module. See RemoteRecord::Config#defaults for the default configuration.

Public Instance Methods

remote_record(remote_record_class: nil, field: :remote_resource_id) { |base_config| ... } click to toggle source
# File lib/remote_record/dsl.rb, line 11
def remote_record(remote_record_class: nil, field: :remote_resource_id)
  klass = DSLPrivate.lookup_and_validate_class(self, remote_record_class)
  base_config = RemoteRecord::Config.defaults
  base_config = yield(base_config) if block_given?
  # Register the field as an Active Record attribute of the remote record
  # class's type
  attribute field, klass::Type[base_config].new

  DSLPrivate.define_remote_scope(self, klass, field)
  DSLPrivate.define_remote_accessor(self, field)
end