Class: QueryHelper::SqlFilter
- Inherits:
-
Object
- Object
- QueryHelper::SqlFilter
- Defined in:
- lib/query_helper/sql_filter.rb
Instance Attribute Summary collapse
-
#column_maps ⇒ Object
Returns the value of attribute column_maps.
-
#filter_values ⇒ Object
Returns the value of attribute filter_values.
Instance Method Summary collapse
- #bind_variables ⇒ Object
- #create_filters ⇒ Object
- #having_clauses ⇒ Object
-
#initialize(filter_values: [], column_maps: []) ⇒ SqlFilter
constructor
A new instance of SqlFilter.
- #where_clauses ⇒ Object
Constructor Details
#initialize(filter_values: [], column_maps: []) ⇒ SqlFilter
Returns a new instance of SqlFilter.
8 9 10 11 |
# File 'lib/query_helper/sql_filter.rb', line 8 def initialize(filter_values: [], column_maps: []) @column_maps = column_maps @filter_values = filter_values end |
Instance Attribute Details
#column_maps ⇒ Object
Returns the value of attribute column_maps.
6 7 8 |
# File 'lib/query_helper/sql_filter.rb', line 6 def column_maps @column_maps end |
#filter_values ⇒ Object
Returns the value of attribute filter_values.
6 7 8 |
# File 'lib/query_helper/sql_filter.rb', line 6 def filter_values @filter_values end |
Instance Method Details
#bind_variables ⇒ Object
39 40 41 |
# File 'lib/query_helper/sql_filter.rb', line 39 def bind_variables Hash[@filters.collect { |f| [f.bind_variable, f.criterion] }] end |
#create_filters ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
35 36 37 |
# File 'lib/query_helper/sql_filter.rb', line 35 def having_clauses @filters.select{ |f| f.aggregate == true }.map(&:sql_string) end |
#where_clauses ⇒ Object
31 32 33 |
# File 'lib/query_helper/sql_filter.rb', line 31 def where_clauses @filters.select{ |f| f.aggregate == false }.map(&:sql_string) end |