Class: ActiveAdmin::Mongoid::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/mongoid/adaptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, search_params = {}, per_page = 30, page = 1) ⇒ Search

Returns a new instance of Search.



6
7
8
9
10
11
12
# File 'lib/active_admin/mongoid/adaptor.rb', line 6

def initialize(object, search_params = {}, per_page = 30, page = 1)
  @base = object
  @search_params = search_params
  @query_hash = get_query_hash(search_params)
  vpage = page.to_i > 0 ? page.to_i : 1
  @query = @base.where(@query_hash).limit(per_page).skip(per_page * (vpage - 1))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/active_admin/mongoid/adaptor.rb', line 18

def method_missing(method_id, *args, &block)
  if is_query(method_id)
    @search_params[method_id.to_s]
  else
    @query.send(method_id, *args, &block)
  end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



4
5
6
# File 'lib/active_admin/mongoid/adaptor.rb', line 4

def base
  @base
end

#queryObject (readonly)

Returns the value of attribute query.



4
5
6
# File 'lib/active_admin/mongoid/adaptor.rb', line 4

def query
  @query
end

#query_hashObject (readonly)

Returns the value of attribute query_hash.



4
5
6
# File 'lib/active_admin/mongoid/adaptor.rb', line 4

def query_hash
  @query_hash
end

#search_paramsObject (readonly)

Returns the value of attribute search_params.



4
5
6
# File 'lib/active_admin/mongoid/adaptor.rb', line 4

def search_params
  @search_params
end

Instance Method Details

#respond_to?(method_id) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/active_admin/mongoid/adaptor.rb', line 14

def respond_to?(method_id)
  @query.send(:respond_to?, method_id)
end