Class: ActiveAdmin::Mongoid::Adaptor::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.



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

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



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

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.



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

def base
  @base
end

#queryObject (readonly)

Returns the value of attribute query.



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

def query
  @query
end

#query_hashObject (readonly)

Returns the value of attribute query_hash.



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

def query_hash
  @query_hash
end

#search_paramsObject (readonly)

Returns the value of attribute search_params.



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

def search_params
  @search_params
end

Instance Method Details

#respond_to?(method_id) ⇒ Boolean

Returns:

  • (Boolean)


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

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