Module: RemoteRecord::DSLPrivate

Defined in:
lib/remote_record/dsl.rb

Overview

Methods private to the DSL module.

Class Method Summary collapse

Class Method Details

.define_remote_accessor(base, field_name) ⇒ Object

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.



47
48
49
50
51
52
53
# 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) ⇒ Object

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



36
37
38
39
40
41
42
# 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) ⇒ Object



28
29
30
31
32
# 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) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# 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) ⇒ Object

Raises:

  • (NotImplementedError.new)


55
56
57
# 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