Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 9, 2024
1 parent fff2ac0 commit 43c6dcf
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/datagrid/drivers/abstract_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def less_equal(scope, field, value)
raise NotImplementedError
end

def has_column?(scope, column_name)
def scope_has_column?(scope, column_name)
raise NotImplementedError
end

Expand Down
8 changes: 4 additions & 4 deletions lib/datagrid/drivers/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def reverse_order(scope)
end

def default_order(scope, column_name)
has_column?(scope, column_name) ? prefix_table_name(scope, column_name) : nil
scope_has_column?(scope, column_name) ? prefix_table_name(scope, column_name) : nil
end

def greater_equal(scope, field, value)
Expand All @@ -75,7 +75,7 @@ def less_equal(scope, field, value)
scope.where(["#{prefix_table_name(scope, field)} <= ?", value])
end

def has_column?(scope, column_name)
def scope_has_column?(scope, column_name)
scope.column_names.include?(column_name.to_s)
rescue ::ActiveRecord::StatementInvalid
false
Expand All @@ -91,7 +91,7 @@ def contains(scope, field, value)
end

def normalized_column_type(scope, field)
return nil unless has_column?(scope, field)
return nil unless scope_has_column?(scope, field)

builtin_type = scope.columns_hash[field.to_s].type
{
Expand Down Expand Up @@ -130,7 +130,7 @@ def can_preload?(scope, association)
protected

def prefix_table_name(scope, field)
has_column?(scope, field) ? [scope.table_name, field].join(".") : field
scope_has_column?(scope, field) ? [scope.table_name, field].join(".") : field
end

def contains_predicate
Expand Down
4 changes: 2 additions & 2 deletions lib/datagrid/drivers/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def less_equal(scope, field, value)
end
end

def has_column?(scope, column_name)
def scope_has_column?(scope, column_name)
scope.any? && scope.first.respond_to?(column_name)
end

def is_timestamp?(scope, column_name)
has_column?(scope, column_name) &&
scope_has_column?(scope, column_name) &&
timestamp_class?(get(scope.first, column_name).class)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/datagrid/drivers/mongo_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def desc(scope, order)
end

def default_order(scope, column_name)
has_column?(scope, column_name) ? column_name : nil
scope_has_column?(scope, column_name) ? column_name : nil
end

def greater_equal(scope, field, value)
Expand All @@ -42,7 +42,7 @@ def less_equal(scope, field, value)
scope.where(field => { "$lte" => value })
end

def has_column?(scope, column_name)
def scope_has_column?(scope, column_name)
scope.key?(column_name)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/datagrid/drivers/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def desc(scope, order)
end

def default_order(scope, column_name)
has_column?(scope, column_name) ? column_name : nil
scope_has_column?(scope, column_name) ? column_name : nil
end

def greater_equal(scope, field, value)
Expand All @@ -47,7 +47,7 @@ def less_equal(scope, field, value)
scope.where(field => { "$lte" => value })
end

def has_column?(scope, column_name)
def scope_has_column?(scope, column_name)
column_names(scope).include?(column_name.to_s)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/datagrid/drivers/sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def desc(scope, order)
end

def default_order(scope, column_name)
has_column?(scope, column_name) ? ::Sequel.lit(prefix_table_name(scope, column_name)) : nil
scope_has_column?(scope, column_name) ? ::Sequel.lit(prefix_table_name(scope, column_name)) : nil
end

def greater_equal(scope, field, value)
Expand All @@ -44,7 +44,7 @@ def less_equal(scope, field, value)
scope.where(::Sequel.lit("#{prefix_table_name(scope, field)} <= ?", value))
end

def has_column?(scope, column_name)
def scope_has_column?(scope, column_name)
scope.columns.include?(column_name.to_sym)
end

Expand Down Expand Up @@ -98,11 +98,11 @@ def can_preload?(scope, association)
protected

def prefix_table_name(scope, field)
has_column?(scope, field) ? [to_scope(scope).row_proc.table_name, field].join(".") : field
scope_has_column?(scope, field) ? [to_scope(scope).row_proc.table_name, field].join(".") : field
end

def column_type(scope, field)
has_column?(scope, field) ? to_scope(scope).row_proc.db_schema[field.to_sym][:type] : nil
scope_has_column?(scope, field) ? to_scope(scope).row_proc.db_schema[field.to_sym][:type] : nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datagrid/filters/base_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def driver
def default_filter(value, scope, _grid)
return nil if dummy?

if !driver.has_column?(scope, name) && scope.respond_to?(name, true)
if !driver.scope_has_column?(scope, name) && scope.respond_to?(name, true)
scope.public_send(name, value)
else
default_filter_where(scope, value)
Expand Down

0 comments on commit 43c6dcf

Please sign in to comment.