Class: Wice::ActiveRecordColumnWrapper
- Defined in:
- lib/wice/active_record_column_wrapper.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#alias_or_table_name(table_alias) ⇒ Object
:nodoc:.
- #array? ⇒ Boolean
-
#initialize(column, all_filter_params, main_table, table_alias, custom_filter_active, filter_type) ⇒ ActiveRecordColumnWrapper
constructor
:nodoc:.
-
#model ⇒ Object
:nodoc:.
-
#name ⇒ Object
:nodoc:.
-
#wg_generate_conditions ⇒ Object
:nodoc:.
-
#wg_initialize_request_parameters ⇒ Object
:nodoc:.
Constructor Details
#initialize(column, all_filter_params, main_table, table_alias, custom_filter_active, filter_type) ⇒ ActiveRecordColumnWrapper
:nodoc:
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wice/active_record_column_wrapper.rb', line 9 def initialize(column, all_filter_params, main_table, table_alias, custom_filter_active, filter_type) #:nodoc: @column = column # nil | Symbol @filter_type = filter_type # Hash { String => String | Array[String]} @all_filter_params = all_filter_params # nil | Boolean @main_table = main_table # nil | String @table_alias = table_alias # nil | Array[String] | Array[Array[...]] | Array[Symbol] @custom_filter_active = custom_filter_active end |
Instance Method Details
#alias_or_table_name(table_alias) ⇒ Object
:nodoc:
128 129 130 |
# File 'lib/wice/active_record_column_wrapper.rb', line 128 def alias_or_table_name(table_alias) #:nodoc: table_alias || @column.model.table_name end |
#array? ⇒ Boolean
118 119 120 121 122 123 124 125 126 |
# File 'lib/wice/active_record_column_wrapper.rb', line 118 def array? if @column..respond_to? :array @column..array else @column..sql_type.index('[]') end rescue false end |
#model ⇒ Object
:nodoc:
114 115 116 |
# File 'lib/wice/active_record_column_wrapper.rb', line 114 def model #:nodoc: @column.model end |
#name ⇒ Object
:nodoc:
110 111 112 |
# File 'lib/wice/active_record_column_wrapper.rb', line 110 def name #:nodoc: @column.name end |
#wg_generate_conditions ⇒ Object
:nodoc:
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/wice/active_record_column_wrapper.rb', line 78 def wg_generate_conditions #:nodoc: return nil if @request_params.nil? if @custom_filter_active custom_processor_klass = ::Wice::Columns.get_conditions_generator_column_processor(:custom) custom_processor = custom_processor_klass.new(self) return custom_processor.generate_conditions(@table_alias, @request_params) end column_type = @filter_type || @column.type.to_s.intern filter_type = case column_type when :date ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATE) when :datetime ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME) when :timestamp ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME) else column_type end processor_class = ::Wice::Columns.get_conditions_generator_column_processor(filter_type) if processor_class return processor_class.new(self, column_type).generate_conditions(@table_alias, @request_params) else Wice.log("No processor for database type #{column_type}!!!") nil end end |
#wg_initialize_request_parameters ⇒ Object
:nodoc:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/wice/active_record_column_wrapper.rb', line 28 def wg_initialize_request_parameters #:nodoc: @request_params = nil return if @all_filter_params.nil? # if the parameter does not specify the table name we only allow columns in the default table to use these parameters if @main_table && @request_params = @all_filter_params[@column.name] current_parameter_name = @column.name elsif @request_params = @all_filter_params[alias_or_table_name(@table_alias) + '.' + @column.name] current_parameter_name = alias_or_table_name(@table_alias) + '.' + @column.name end # Preprocess incoming parameters for datetime, if what's coming in is # a datetime (with custom_filter it can be anything else, and not # the datetime hash {fr: ..., to: ...}) if @request_params if (@column.type == :datetime || @column.type == :timestamp) && @request_params.is_a?(Hash) [:fr, :to].each do |sym| if @request_params[sym] if @request_params[sym].is_a?(String) @request_params[sym] = Wice::ConfigurationProvider.value_for(:DATETIME_PARSER).call(@request_params[sym]) elsif @request_params[sym].is_a?(Hash) @request_params[sym] = Wice::GridTools.params_2_datetime(@request_params[sym]) end end end end # Preprocess incoming parameters for date, if what's coming in is # a date (with custom_filter it can be anything else, and not # the date hash {fr: ..., to: ...}) if @column.type == :date && @request_params.is_a?(Hash) [:fr, :to].each do |sym| if @request_params[sym] if @request_params[sym].is_a?(String) @request_params[sym] = Wice::ConfigurationProvider.value_for(:DATE_PARSER).call(@request_params[sym]) elsif @request_params[sym].is_a?(Hash) @request_params[sym] = ::Wice::GridTools.params_2_date(@request_params[sym]) end end end end end [wg_generate_conditions, current_parameter_name] end |