Class: RailsAdmin::Adapters::ActiveRecord::WhereBuilder
- Inherits:
-
Object
- Object
- RailsAdmin::Adapters::ActiveRecord::WhereBuilder
- Defined in:
- lib/rails_admin/adapters/active_record.rb
Instance Method Summary collapse
- #add(field, value, operator) ⇒ Object
- #build ⇒ Object
-
#initialize(scope) ⇒ WhereBuilder
constructor
A new instance of WhereBuilder.
Constructor Details
#initialize(scope) ⇒ WhereBuilder
Returns a new instance of WhereBuilder.
172 173 174 175 176 177 |
# File 'lib/rails_admin/adapters/active_record.rb', line 172 def initialize(scope) @statements = [] @values = [] @tables = [] @scope = scope end |
Instance Method Details
#add(field, value, operator) ⇒ Object
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/rails_admin/adapters/active_record.rb', line 179 def add(field, value, operator) field.searchable_columns.flatten.each do |column_infos| statement, value1, value2 = StatementBuilder.new(column_infos[:column], column_infos[:type], value, operator, @scope.connection.adapter_name).to_statement @statements << statement if statement.present? @values << value1 unless value1.nil? @values << value2 unless value2.nil? table, column = column_infos[:column].split('.') @tables.push(table) if column end end |
#build ⇒ Object
190 191 192 193 194 |
# File 'lib/rails_admin/adapters/active_record.rb', line 190 def build scope = @scope.where(@statements.join(' OR '), *@values) scope = scope.references(*@tables.uniq) if @tables.any? scope end |