Module: Ransack::Adapters::Mongoid::Base::ClassMethods

Defined in:
lib/ransack/adapters/mongoid/base.rb

Instance Method Summary collapse

Instance Method Details

#_ransackersObject


36
37
38
# File 'lib/ransack/adapters/mongoid/base.rb', line 36

def _ransackers
  @_ransackers ||= {}
end

#_ransackers=(value) ⇒ Object


40
41
42
# File 'lib/ransack/adapters/mongoid/base.rb', line 40

def _ransackers=(value)
  @_ransackers = value
end

#all_ransackable_attributesObject


57
58
59
# File 'lib/ransack/adapters/mongoid/base.rb', line 57

def all_ransackable_attributes
  ['id'] + column_names.select { |c| c != '_id' } + _ransackers.keys
end

#column_namesObject


106
107
108
# File 'lib/ransack/adapters/mongoid/base.rb', line 106

def column_names
  @column_names ||= fields.map(&:first)
end

#columnsObject

def group_by *args, &block

criteria

end


102
103
104
# File 'lib/ransack/adapters/mongoid/base.rb', line 102

def columns
  @columns ||= fields.map(&:second).map{ |c| ColumnWrapper.new(c) }
end

#columns_hashObject


110
111
112
# File 'lib/ransack/adapters/mongoid/base.rb', line 110

def columns_hash
  columns.index_by(&:name)
end

#first(*args) ⇒ Object


90
91
92
93
94
95
96
# File 'lib/ransack/adapters/mongoid/base.rb', line 90

def first(*args)
  if args.size == 0
    super
  else
    self.criteria.limit(args.first)
  end
end

#joins_values(*args) ⇒ Object

imitating active record


86
87
88
# File 'lib/ransack/adapters/mongoid/base.rb', line 86

def joins_values *args
  []
end

#ransack(params = {}, options = {}) ⇒ Object Also known as: search


44
45
46
47
48
# File 'lib/ransack/adapters/mongoid/base.rb', line 44

def ransack(params = {}, options = {})
  params = params.presence || {}
  Search.new(self, params ? params.delete_if {
    |k, v| v.blank? && v != false } : params, options)
end

#ransackable_associations(auth_object = nil) ⇒ Object


71
72
73
# File 'lib/ransack/adapters/mongoid/base.rb', line 71

def ransackable_associations(auth_object = nil)
  reflect_on_all_associations_all.map { |a| a.name.to_s }
end

#ransackable_attributes(auth_object = nil) ⇒ Object


61
62
63
# File 'lib/ransack/adapters/mongoid/base.rb', line 61

def ransackable_attributes(auth_object = nil)
  all_ransackable_attributes
end

#ransackable_scopes(auth_object = nil) ⇒ Object

For overriding with a whitelist of symbols


80
81
82
# File 'lib/ransack/adapters/mongoid/base.rb', line 80

def ransackable_scopes(auth_object = nil)
  []
end

#ransacker(name, opts = {}, &block) ⇒ Object


52
53
54
55
# File 'lib/ransack/adapters/mongoid/base.rb', line 52

def ransacker(name, opts = {}, &block)
  self._ransackers = _ransackers.merge name.to_s => Ransacker
    .new(self, name, opts, &block)
end

#ransortable_attributes(auth_object = nil) ⇒ Object


65
66
67
68
69
# File 'lib/ransack/adapters/mongoid/base.rb', line 65

def ransortable_attributes(auth_object = nil)
  # Here so users can overwrite the attributes
  # that show up in the sort_select
  ransackable_attributes(auth_object)
end

#reflect_on_all_associations_allObject


75
76
77
# File 'lib/ransack/adapters/mongoid/base.rb', line 75

def reflect_on_all_associations_all
  reflect_on_all_associations(:belongs_to, :has_one, :has_many)
end

#tableObject


114
115
116
117
118
119
# File 'lib/ransack/adapters/mongoid/base.rb', line 114

def table
  name = ::Ransack::Adapters::Mongoid::Attributes::Attribute.new(self.criteria, :name)
  {
    :name => name
  }
end