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

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

Instance Method Summary collapse

Instance Method Details

#all_ransackable_attributesObject


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

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

#column_namesObject


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

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

#columnsObject

def group_by *args, &block

criteria

end


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

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

#columns_hashObject


118
119
120
# File 'lib/ransack/adapters/mongoid/base.rb', line 118

def columns_hash
  columns.index_by(&:name)
end

#custom_join_ast(*args) ⇒ Object


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

def custom_join_ast *args
  []
end

#first(*args) ⇒ Object


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

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

#joins_values(*args) ⇒ Object

imitating active record


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

def joins_values *args
  []
end

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


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

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

#ransack_alias(new_name, old_name) ⇒ Object


48
49
50
51
# File 'lib/ransack/adapters/mongoid/base.rb', line 48

def ransack_alias(new_name, old_name)
  self._ransack_aliases = _ransack_aliases.merge new_name.to_s =>
    old_name.to_s
end

#ransackable_associations(auth_object = nil) ⇒ Object


73
74
75
# File 'lib/ransack/adapters/mongoid/base.rb', line 73

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

#ransackable_attributes(auth_object = nil) ⇒ Object


63
64
65
# File 'lib/ransack/adapters/mongoid/base.rb', line 63

def ransackable_attributes(auth_object = nil)
  all_ransackable_attributes
end

#ransackable_scopes(auth_object = nil) ⇒ Object

For overriding with a whitelist of symbols


84
85
86
# File 'lib/ransack/adapters/mongoid/base.rb', line 84

def ransackable_scopes(auth_object = nil)
  []
end

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


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

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


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

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


77
78
79
80
81
# File 'lib/ransack/adapters/mongoid/base.rb', line 77

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

#tableObject


122
123
124
125
126
127
# File 'lib/ransack/adapters/mongoid/base.rb', line 122

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