Sha256: 27bdbdc1e41e23eaea00a57f5979bf8afbcf1e74f872f8a48a1085004e238758

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

class Tabulatr::Adapter::MongoidAdapter < Tabulatr::Adapter
  def primary_key
    :id
  end

  def key_type
    :string
  end

  def selected_ids(opts)
    preconditions_scope(opts).only(:id)
  end

  def table_name
    if Object.const_defined?("Mongoid") && @relation.is_a?(Mongoid::Criteria)
      @relation.klass
    else
      @relation
    end.to_s.tableize.gsub('/','_')
  end

  def table_name_for_association(assoc)
    assoc.to_s.tableize
  end

  def order_for_query(sortparam, default)
    context = order(sortparam, default)
    context.values.map(&:to_s) if context
  end

  def includes(includes)
    @relation   # do nothing with includes
  end

  def add_conditions_from(n,v)
    if v.is_a?(String)
      nn = n.split('.').last
      @relation = @relation.where(nn => v) unless v.blank?
    elsif v.is_a?(Hash)
      if v[:like].present?
        nn = n.split('.').last
        @relation = @relation.where(nn => Regexp.new(v[:like]))
      else
        nn = n.split('.').last.to_sym
        @relation = @relation.where(nn.gte => v[:from]) if v[:from].present?
        @relation = @relation.where(nn.lte => v[:to]) if v[:to].present?
      end
    else
      raise "Wrong filter type: #{v.class}"
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tabulatr-0.4.1 lib/tabulatr/tabulatr/adapter/mongoid.rb
tabulatr-0.4.0 lib/tabulatr/tabulatr/adapter/mongoid.rb