Class: Babik::QuerySet::Where

Inherits:
Object
  • Object
show all
Defined in:
lib/babik/queryset/components/where.rb

Overview

Where conditions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Where

Returns a new instance of Where.



12
13
14
15
16
# File 'lib/babik/queryset/components/where.rb', line 12

def initialize(model)
  @model = model
  @inclusion_filters = []
  @exclusion_filters = []
end

Instance Attribute Details

#exclusion_filtersObject (readonly)

Returns the value of attribute exclusion_filters.



10
11
12
# File 'lib/babik/queryset/components/where.rb', line 10

def exclusion_filters
  @exclusion_filters
end

#inclusion_filtersObject (readonly)

Returns the value of attribute inclusion_filters.



10
11
12
# File 'lib/babik/queryset/components/where.rb', line 10

def inclusion_filters
  @inclusion_filters
end

#modelObject (readonly)

Returns the value of attribute model.



10
11
12
# File 'lib/babik/queryset/components/where.rb', line 10

def model
  @model
end

Instance Method Details

#add_exclusion_filter(filter) ⇒ Object



26
27
28
# File 'lib/babik/queryset/components/where.rb', line 26

def add_exclusion_filter(filter)
  @exclusion_filters << Babik::QuerySet::Condition.factory(@model, filter)
end

#add_inclusion_filter(filter) ⇒ Object



30
31
32
# File 'lib/babik/queryset/components/where.rb', line 30

def add_inclusion_filter(filter)
  @inclusion_filters << Babik::QuerySet::Condition.factory(@model, filter)
end

#exclusion_filters?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/babik/queryset/components/where.rb', line 18

def exclusion_filters?
  @exclusion_filters.length.positive?
end

#inclusion_filters?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/babik/queryset/components/where.rb', line 22

def inclusion_filters?
  @inclusion_filters.length.positive?
end

#left_joins_by_aliasObject



34
35
36
37
38
39
40
# File 'lib/babik/queryset/components/where.rb', line 34

def left_joins_by_alias
  left_joins_by_alias = {}
  [@inclusion_filters, @exclusion_filters].flatten.each do |filter|
    left_joins_by_alias.merge!(filter.left_joins_by_alias)
  end
  left_joins_by_alias
end