Module: BabySqueel::Compat::QueryMethods

Defined in:
lib/baby_squeel/compat.rb

Instance Method Summary collapse

Instance Method Details

#group(*args, &block) ⇒ Object

Overrides ActiveRecord::QueryMethods#group



65
66
67
68
69
70
71
# File 'lib/baby_squeel/compat.rb', line 65

def group(*args, &block)
  if block_given? && args.empty?
    grouping(&block)
  else
    super
  end
end

#having(*args, &block) ⇒ Object

Overrides ActiveRecord::QueryMethods#having



74
75
76
77
78
79
80
# File 'lib/baby_squeel/compat.rb', line 74

def having(*args, &block)
  if block_given? && args.empty?
    when_having(&block)
  else
    super
  end
end

#joins(*args, &block) ⇒ Object

Overrides ActiveRecord::QueryMethods#joins



31
32
33
34
35
36
37
# File 'lib/baby_squeel/compat.rb', line 31

def joins(*args, &block)
  if block_given? && args.empty?
    joining(&block)
  else
    super
  end
end

#order(*args, &block) ⇒ Object

Overrides ActiveRecord::QueryMethods#order



56
57
58
59
60
61
62
# File 'lib/baby_squeel/compat.rb', line 56

def order(*args, &block)
  if block_given? && args.empty?
    ordering(&block)
  else
    super
  end
end

#select(*args, &block) ⇒ Object

Heads up, Array#select conflicts with ActiveRecord::QueryMethods#select. So, if arity is given to the block, we’ll use Array#select. Otherwise, you’ll be in a DSL block.

Model.select { This is DSL }
Model.select { |m| This is not DSL }


47
48
49
50
51
52
53
# File 'lib/baby_squeel/compat.rb', line 47

def select(*args, &block)
  if block_given? && args.empty? && block.arity.zero?
    selecting(&block)
  else
    super
  end
end

#where(*args, &block) ⇒ Object

Overrides ActiveRecord::QueryMethods#where



83
84
85
86
87
88
89
# File 'lib/baby_squeel/compat.rb', line 83

def where(*args, &block)
  if block_given? && args.empty?
    where.has(&block)
  else
    super
  end
end