class Datagrid::Drivers::Mongoid
@!visibility private
Public Class Methods
Source
# File lib/datagrid/drivers/mongoid.rb, line 7 def self.match?(scope) return false unless defined?(::Mongoid) if scope.is_a?(Class) scope.ancestors.include?(::Mongoid::Document) else scope.is_a?(::Mongoid::Criteria) end end
Public Instance Methods
Source
# File lib/datagrid/drivers/mongoid.rb, line 30 def asc(scope, order) scope.asc(order) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 83 def batch_each(scope, batch_size, &block) current_page = 0 loop do batch = scope.skip(current_page * batch_size).limit(batch_size).to_a return if batch.empty? scope.skip(current_page * batch_size).limit(batch_size).each(&block) current_page += 1 end end
Source
# File lib/datagrid/drivers/mongoid.rb, line 102 def can_preload?(scope, association) !!scope.klass.reflect_on_association(association) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 58 def column_names(scope) to_scope(scope).klass.fields.keys end
Source
# File lib/datagrid/drivers/mongoid.rb, line 54 def contains(scope, field, value) scope.where(field => Regexp.compile(Regexp.escape(value))) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 94 def default_cache_key(asset) asset.id || raise(NotImplementedError) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 38 def default_order(scope, column_name) scope_has_column?(scope, column_name) ? column_name : nil end
Source
# File lib/datagrid/drivers/mongoid.rb, line 98 def default_preload(scope, value) scope.includes(value) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 34 def desc(scope, order) scope.desc(order) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 42 def greater_equal(scope, field, value) scope.where(field => { "$gte" => value }) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 46 def less_equal(scope, field, value) scope.where(field => { "$lte" => value }) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 62 def normalized_column_type(scope, field) type = to_scope(scope).klass.fields[field.to_s]&.type return nil unless type { [BigDecimal, String, Symbol, Range, Array, Hash] => :string, [::Mongoid::Boolean] => :boolean, [Date] => :date, TIMESTAMP_CLASSES => :timestamp, [Float] => :float, [Integer] => :integer, }.each do |keys, value| return value if keys.include?(type) end :string end
Source
# File lib/datagrid/drivers/mongoid.rb, line 50 def scope_has_column?(scope, column_name) column_names(scope).include?(column_name.to_s) end
Source
# File lib/datagrid/drivers/mongoid.rb, line 17 def to_scope(scope) if scope.respond_to?(:all) scope.all else scope.where(nil) end end
Source
# File lib/datagrid/drivers/mongoid.rb, line 25 def where(scope, attribute, value) value = { "$gte" => value.first, "$lte" => value.last } if value.is_a?(Range) scope.where(attribute => value) end