class QueryHelper::SqlFilter
Attributes
column_maps[RW]
filter_values[RW]
Public Class Methods
new(filter_values: [], column_maps: [])
click to toggle source
# File lib/query_helper/sql_filter.rb, line 8 def initialize(filter_values: [], column_maps: []) @column_maps = column_maps @filter_values = filter_values end
Public Instance Methods
bind_variables()
click to toggle source
# File lib/query_helper/sql_filter.rb, line 39 def bind_variables Hash[@filters.collect { |f| [f.bind_variable, f.criterion] }] end
create_filters()
click to toggle source
# File lib/query_helper/sql_filter.rb, line 13 def create_filters @filters = [] @filter_values.each do |comparate_alias, criteria| # Find the sql mapping if it exists map = @column_maps.find { |m| m.alias_name == comparate_alias } raise InvalidQueryError.new("cannot filter by #{comparate_alias}") unless map # create the filter @filters << QueryHelper::Filter.new( operator_code: criteria.keys.first, criterion: criteria.values.first, comparate: map.sql_expression, aggregate: map.aggregate ) end end
having_clauses()
click to toggle source
# File lib/query_helper/sql_filter.rb, line 35 def having_clauses @filters.select{ |f| f.aggregate == true }.map(&:sql_string) end
where_clauses()
click to toggle source
# File lib/query_helper/sql_filter.rb, line 31 def where_clauses @filters.select{ |f| f.aggregate == false }.map(&:sql_string) end