module RemoteRecord::DSLPrivate

Methods private to the DSL module.

Public Class Methods

define_remote_accessor(base, field_name) click to toggle source

Define the remote accessor for instances - this uses the Active Record type, but adds a reference to the parent object into the config to be used in authorization.

# File lib/remote_record/dsl.rb, line 47
def define_remote_accessor(base, field_name)
  return if base.instance_methods(false).include?(:remote)

  base.define_method(:remote) do |id_field = field_name|
    self[id_field].tap { |record| record.remote_record_config.merge!(authorization_source: self) }
  end
end
define_remote_scope(base, klass, field_name) click to toggle source

Define the remote scope, which returns a Collection for the given Remote Record class

# File lib/remote_record/dsl.rb, line 36
def define_remote_scope(base, klass, field_name)
  return if base.respond_to?(:remote)

  base.define_singleton_method(:remote) do |id_field = field_name, config: nil|
    klass::Collection.new(all, config, id: id_field)
  end
end
lookup_and_validate_class(klass, override) click to toggle source
# File lib/remote_record/dsl.rb, line 28
def lookup_and_validate_class(klass, override)
  RemoteRecord::ClassLookup.new(klass).remote_record_class(override).tap do |found_klass|
    validate_responds_to_get(found_klass)
  end
end
responds_to_get?(klass) click to toggle source
# File lib/remote_record/dsl.rb, line 59
def responds_to_get?(klass)
  klass.instance_methods(false).include? :get
end
validate_responds_to_get(klass) click to toggle source
# File lib/remote_record/dsl.rb, line 55
def validate_responds_to_get(klass)
  raise NotImplementedError.new, 'The remote record does not implement #get.' unless responds_to_get?(klass)
end