class ActiveAny::Relation

Constants

CLAUSE_METHODS
MULTI_VALUE_METHODS
SINGLE_VALUE_METHODS
VALUE_METHODS

Attributes

klass[R]
loaded[R]

Public Class Methods

new(klass) click to toggle source
# File lib/active_any/relation.rb, line 23
def initialize(klass)
  @klass = klass
  @records = []
  @loaded = false
  @values = {}
end

Public Instance Methods

eager_loading?() click to toggle source
# File lib/active_any/relation.rb, line 82
def eager_loading?
  false
end
initialize_copy(*) click to toggle source
Calls superclass method
# File lib/active_any/relation.rb, line 61
def initialize_copy(*)
  @values = @values.dup
  reset
  super
end
inspect() click to toggle source
# File lib/active_any/relation.rb, line 93
def inspect
  subject = loaded? ? records : self
  entries = subject.take([limit_value, 11].compact.min).map!(&:inspect)

  entries[10] = '...' if entries.size == 11

  "#<#{self.class.name} [#{entries.join(', ')}]>"
end
load() click to toggle source
# File lib/active_any/relation.rb, line 77
def load
  exec_query unless loaded
  self
end
loaded?() click to toggle source
# File lib/active_any/relation.rb, line 73
def loaded?
  @loaded
end
merge(other) click to toggle source
# File lib/active_any/relation.rb, line 34
def merge(other)
  if other.is_a?(Array)
    records & other
  elsif other
    spawn.merge!(other)
  else
    raise ArgumentError, "invalid argument: #{other.inspect}."
  end
end
records() click to toggle source
# File lib/active_any/relation.rb, line 56
def records
  load
  @records
end
reset() click to toggle source
# File lib/active_any/relation.rb, line 67
def reset
  @loaded = nil
  @records = [].freeze
  self
end
scoping() { || ... } click to toggle source
# File lib/active_any/relation.rb, line 86
def scoping
  # previous, klass.current_scope = klass.current_scope, self
  yield
  # ensure
  # klass.current_scope = previous
end
to_a() click to toggle source
# File lib/active_any/relation.rb, line 30
def to_a
  records.dup
end

Private Instance Methods

build_preloader() click to toggle source
# File lib/active_any/relation.rb, line 137
def build_preloader
  ActiveAny::Associations::Preloader.new
end
clauses() click to toggle source
# File lib/active_any/relation.rb, line 108
def clauses
  {
    where_clause: where_clause,
    limit_value: limit_value,
    group_values: group_values,
    order_clause: order_clause
  }
end
exec_query() click to toggle source
# File lib/active_any/relation.rb, line 117
def exec_query
  ActiveSupport::Notifications.instrument('exec_query.active_any', clauses: clauses, class_name: klass.name) do
    @records = klass.find_by_query(clauses)
    preload_records(@records)
    @loaded = true
  end
end
preload_records(records) click to toggle source
# File lib/active_any/relation.rb, line 125
def preload_records(records)
  # TODO: implement preload
  # preload = preload_values
  preload = []
  preload += includes_values unless eager_loading?
  preloader = nil
  preload.each do |associations|
    preloader ||= build_preloader
    preloader.preload records, associations
  end
end
spawn() click to toggle source
# File lib/active_any/relation.rb, line 104
def spawn
  clone
end