class Restforce::DB::Strategies::Associated

Restforce::DB::Strategies::Associated defines an initialization strategy for a mapping in which newly-discovered records should only be synchronized into the other system when a specific associated record has already been synchronized.

Public Class Methods

new(with:) click to toggle source

Public: Initialize a Restforce::DB::Strategies::Associated for the passed mapping.

with - A Symbol name of the association which should be checked.

# File lib/restforce/db/strategies/associated.rb, line 17
def initialize(with:)
  @association = with.to_sym
end

Public Instance Methods

build?(record) click to toggle source

Public: Should the passed record be constructed in the other system?

record - A Restforce::DB::Instances::Base.

Returns a Boolean.

# File lib/restforce/db/strategies/associated.rb, line 26
def build?(record)
  !record.synced? && target_association(record.mapping).synced_for?(record)
end
passive?() click to toggle source

Public: Is this a passive sync strategy?

Returns false.

# File lib/restforce/db/strategies/associated.rb, line 33
def passive?
  false
end

Private Instance Methods

target_association(mapping) click to toggle source

Internal: Get the target association for the desired associated record lookup.

mapping - A Restforce::DB::Mapping

Returns a Restforce::DB::Associations::Base.

# File lib/restforce/db/strategies/associated.rb, line 45
def target_association(mapping)
  @target_association ||= mapping.associations.detect do |association|
    association.name == @association
  end
  @target_association || raise(ArgumentError, ":with must correspond to a defined association")
end