Class: Babik::QuerySet::AbstractBase
- Inherits:
-
Object
- Object
- Babik::QuerySet::AbstractBase
- Includes:
- Aggregatable, Bounded, Clonable, Countable, Deletable, Distinguishable, Filterable, Limitable, Lockable, NoneQuerySet, Projectable, RelatedSelector, SQLRenderizable, SetOperations, Sortable, Updatable, Enumerable
- Defined in:
- lib/babik/queryset.rb
Overview
Abstract Base class for QuerySet, implements a container for database results.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_aggregation ⇒ Object
(also: #aggregation?)
readonly
Returns the value of attribute _aggregation.
-
#_count ⇒ Object
(also: #count?)
readonly
Returns the value of attribute _count.
-
#_distinct ⇒ Object
(also: #distinct?)
readonly
Returns the value of attribute _distinct.
-
#_limit ⇒ Object
readonly
Returns the value of attribute _limit.
-
#_lock_type ⇒ Object
readonly
Returns the value of attribute _lock_type.
-
#_order ⇒ Object
readonly
Returns the value of attribute _order.
-
#_projection ⇒ Object
readonly
Returns the value of attribute _projection.
-
#_select_related ⇒ Object
(also: #select_related?)
readonly
Returns the value of attribute _select_related.
-
#_where ⇒ Object
readonly
Returns the value of attribute _where.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
-
._execute_sql(sql) ⇒ Object
Execute SQL code.
Instance Method Summary collapse
-
#all ⇒ ResultSet
Return a ResultSet with the ActiveRecord objects that match the condition given by the filters.
-
#each(&block) ⇒ Object
Loop through the results with a block.
-
#initialize(model_class) ⇒ AbstractBase
constructor
A new instance of AbstractBase.
-
#left_joins_by_alias ⇒ Hash
Get the left joins grouped by alias in a hash.
Methods included from Updatable
Methods included from Sortable
#disorder!, #invert_order!, #order!, #order_by!, #ordered?
Methods included from SetOperations
#difference, #intersection, #union
Methods included from RelatedSelector
Methods included from SQLRenderizable
Methods included from Projectable
#project!, #projection?, #unproject!
Methods included from Lockable
Methods included from Limitable
#[], #exists?, #fetch, #limit!, #limit?, #unlimit!
Methods included from Filterable
Methods included from Distinguishable
Methods included from NoneQuerySet
Methods included from Deletable
Methods included from Countable
#count, #empty?, #exists?, #length, #size
Methods included from Clonable
#clone, #method_missing, #mutate_clone, #respond_to_missing?
Methods included from Bounded
#earliest, #first, #last, #latest
Methods included from Aggregatable
Constructor Details
#initialize(model_class) ⇒ AbstractBase
Returns a new instance of AbstractBase.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/babik/queryset.rb', line 69 def initialize(model_class) @model = model_class @_count = false @_distinct = false @_order = nil @_lock_type = nil @_where = Babik::QuerySet::Where.new(@model) @_aggregation = nil @_limit = nil @_projection = nil @_select_related = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Babik::QuerySet::Clonable
Instance Attribute Details
#_aggregation ⇒ Object (readonly) Also known as: aggregation?
Returns the value of attribute _aggregation.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _aggregation @_aggregation end |
#_count ⇒ Object (readonly) Also known as: count?
Returns the value of attribute _count.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _count @_count end |
#_distinct ⇒ Object (readonly) Also known as: distinct?
Returns the value of attribute _distinct.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _distinct @_distinct end |
#_limit ⇒ Object (readonly)
Returns the value of attribute _limit.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _limit @_limit end |
#_lock_type ⇒ Object (readonly)
Returns the value of attribute _lock_type.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _lock_type @_lock_type end |
#_order ⇒ Object (readonly)
Returns the value of attribute _order.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _order @_order end |
#_projection ⇒ Object (readonly)
Returns the value of attribute _projection.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _projection @_projection end |
#_select_related ⇒ Object (readonly) Also known as:
Returns the value of attribute _select_related.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def @_select_related end |
#_where ⇒ Object (readonly)
Returns the value of attribute _where.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def _where @_where end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
58 59 60 |
# File 'lib/babik/queryset.rb', line 58 def model @model end |
Class Method Details
._execute_sql(sql) ⇒ Object
Execute SQL code
116 117 118 |
# File 'lib/babik/queryset.rb', line 116 def self._execute_sql(sql) ActiveRecord::Base.connection.exec_query(sql) end |
Instance Method Details
#all ⇒ ResultSet
Return a ResultSet with the ActiveRecord objects that match the condition given by the filters.
84 85 86 87 88 89 |
# File 'lib/babik/queryset.rb', line 84 def all sql_select = self.sql.select return @_projection.apply_transforms(self.class._execute_sql(sql_select)) if @_projection return @_select_related.(self.class._execute_sql(sql_select)) if @_select_related @model.find_by_sql(sql_select) end |
#each(&block) ⇒ Object
Loop through the results with a block
93 94 95 |
# File 'lib/babik/queryset.rb', line 93 def each(&block) self.all.each(&block) end |
#left_joins_by_alias ⇒ Hash
Get the left joins grouped by alias in a hash.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/babik/queryset.rb', line 99 def left_joins_by_alias left_joins_by_alias = {} # Merge where left_joins_by_alias.merge!(@_where.left_joins_by_alias) # Merge order left_joins_by_alias.merge!(@_order.left_joins_by_alias) if @_order # Merge aggregation left_joins_by_alias.merge!(@_aggregation.left_joins_by_alias) if @_aggregation # Merge prefetchs left_joins_by_alias.merge!(@_select_related.left_joins_by_alias) if @_select_related # Return the left joins by alias left_joins_by_alias end |