Module: Fancygrid::Orm::SqlGenerator

Included in:
ActiveRecord
Defined in:
lib/fancygrid/orm/sql_generator.rb

Overview

:nodoc:

Constant Summary collapse

OPERATOR_NAMES =
[
  :equal, :not_equal, :less, :less_equal, :greater, :greater_equal, :starts_with, :ends_with, 
  :like, :is_null, :is_not_null, :is_true, :is_not_true, :is_false, :is_not_false, :in, :not_in
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#query_optionsObject

Returns the value of attribute query_options.



10
11
12
# File 'lib/fancygrid/orm/sql_generator.rb', line 10

def query_options
  @query_options
end

Instance Method Details

#execute(resource_class) ⇒ Object



34
35
36
# File 'lib/fancygrid/orm/sql_generator.rb', line 34

def execute resource_class
  raise "called execute on abstract class"
end

#initialize(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fancygrid/orm/sql_generator.rb', line 12

def initialize(options)

  self.query_options = {}
  
  if grid = options[:grid]
    self.query_options[:order] = grid.view_state.sql_order
  end
  
  if select = options[:select]
    self.query_options[:select] = select
  end
  
  if pagination = options[:pagination]
    self.query_options[:limit] = pagination[:per_page].to_i
    self.query_options[:offset] = (pagination[:page].to_i - 1) * pagination[:per_page].to_i
  end
  
  if conditions = self.build_conditions(options[:operator], options[:conditions])
    self.query_options[:conditions] = conditions
  end
end