class SequelMapper::ManyToManyAssociation::JoinedDataset

Public Class Methods

new(records, join_records) click to toggle source
# File lib/sequel_mapper/many_to_many_association.rb, line 62
def initialize(records, join_records)
  @records = records
  @join_records = join_records
end

Public Instance Methods

join(_relation_name, _conditions) click to toggle source
# File lib/sequel_mapper/many_to_many_association.rb, line 67
def join(_relation_name, _conditions)
  # TODO: This works for the current test suite but is probably too
  # simplistic. Perhaps if the dataset was aware of its join conditions
  # it would be able to intellegently skip joining or delegate
  self
end
where(criteria) click to toggle source
# File lib/sequel_mapper/many_to_many_association.rb, line 74
def where(criteria)
  self.class.new(
    *decompose_set(
      find_like_sequel(criteria)
    )
  )
end

Private Instance Methods

decompose_set(set) click to toggle source
# File lib/sequel_mapper/many_to_many_association.rb, line 84
def decompose_set(set)
  set.map(&:to_pair).transpose.+([ [], [] ]).take(2)
end
find_like_sequel(criteria) click to toggle source
# File lib/sequel_mapper/many_to_many_association.rb, line 88
def find_like_sequel(criteria)
  joined_records
    .select { |record|
      criteria.all? { |k, v|
        record.fetch(k, :nope) == v
      }
    }
end
joined_records() click to toggle source
# File lib/sequel_mapper/many_to_many_association.rb, line 97
def joined_records
  # TODO: there will inevitably nearly always be a mismatch between the
  # number of records and unique join records. This zip/transpose
  # approach may be too simplistic.
  @joined_records ||= records
    .zip(@join_records)
    .map { |record, join_record|
      JoinedRecord.new(record, join_record)
    }
end