Module: ActiveScaffold::CalendarDateSelectBridge::Finder::ClassMethods

Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb

Instance Method Summary collapse

Instance Method Details

#condition_for_calendar_date_select_type(column, value, like_pattern = nil) ⇒ Object

AST



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb', line 111

def condition_for_calendar_date_select_type(column, value, like_pattern = nil)
  return nil if value['from'].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value['opt'])
  conversion = column.column.type == :date ? 'to_date' : 'to_time'
  from_value, to_value = ['from', 'to'].collect do |field|
    Time.zone.parse(value[field]) rescue nil
  end
  if value['opt'] == 'BETWEEN'
    ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)]
  else
    ["#{column.search_sql} #{value['opt']} ?", from_value.send(conversion).to_s(:db)]
  end
end