Class: AnyQuery::Query Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/any_query/query.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(model, adapter) ⇒ Query

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Query.



10
11
12
13
# File 'lib/any_query/query.rb', line 10

def initialize(model, adapter)
  @model = model
  @adapter = adapter
end

Instance Method Details

#each(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/any_query/query.rb', line 43

def each(&block)
  to_a.each(&block)
end

#find(id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/any_query/query.rb', line 35

def find(id)
  @adapter.load_single(@model, id, [])
end

#joins(model, primary_key, foreign_key, into:, as: :single, strategy: :default) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/any_query/query.rb', line 15

def joins(model, primary_key, foreign_key, into:, as: :single, strategy: :default)
  dup.joins!(model, primary_key, foreign_key, into:, as:, strategy:)
end

#joins!(model, primary_key, foreign_key, into:, as: :single, strategy: :default) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
# File 'lib/any_query/query.rb', line 47

def joins!(model, primary_key, foreign_key, into:, as: :single, strategy: :default)
  @joins ||= []
  @joins << ({ model:, primary_key:, foreign_key:, into:, as:, strategy: })
  self
end

#limit(limit) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
# File 'lib/any_query/query.rb', line 31

def limit(limit)
  dup.limit!(limit)
end

#limit!(limit) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
68
# File 'lib/any_query/query.rb', line 65

def limit!(limit)
  @limit = limit
  self
end

#select(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
# File 'lib/any_query/query.rb', line 27

def select(*args)
  dup.select!(*args)
end

#select!(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
# File 'lib/any_query/query.rb', line 53

def select!(*args)
  @select ||= []
  @select += args
  self
end

#to_aObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/any_query/query.rb', line 39

def to_a
  @adapter.load(@model, select: @select, joins: @joins, where: @where, limit: @limit)
end

#where(options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# File 'lib/any_query/query.rb', line 23

def where(options)
  dup.where!(options)
end

#where!(options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



59
60
61
62
63
# File 'lib/any_query/query.rb', line 59

def where!(options)
  @where ||= []
  @where << options
  self
end

#with_singleObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/any_query/query.rb', line 19

def with_single
  dup.joins!(:show, :id, :id, into: :single, as: :single, strategy: :single)
end