Class: ActiveAdmin::SearchableSelect::OptionCollection Private

Inherits:
Object
  • Object
show all
Defined in:
lib/activeadmin/searchable_select/option_collection.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ OptionCollection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of OptionCollection.

API:

  • private



5
6
7
8
9
10
11
# File 'lib/activeadmin/searchable_select/option_collection.rb', line 5

def initialize(name, options)
  @name = name
  @scope = extract_scope_option(options)
  @display_text = extract_display_text_option(options)
  @filter = extract_filter_option(options)
  @per_page = options.fetch(:per_page, 10)
end

Instance Method Details

#as_json(template, params) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/activeadmin/searchable_select/option_collection.rb', line 34

def as_json(template, params)
  records, more = fetch_records(template, params)

  results = records.map do |record|
    {
      id: record.id,
      text: display_text(record)
    }
  end

  { results: results, pagination: { more: more } }
end

#collection_action_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



30
31
32
# File 'lib/activeadmin/searchable_select/option_collection.rb', line 30

def collection_action_name
  "#{@name}_options"
end

#display_text(record) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



26
27
28
# File 'lib/activeadmin/searchable_select/option_collection.rb', line 26

def display_text(record)
  @display_text.call(record)
end

#scope(template, params) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/activeadmin/searchable_select/option_collection.rb', line 13

def scope(template, params)
  case @scope
  when Proc
    if @scope.arity.zero?
      template.instance_exec(&@scope)
    else
      template.instance_exec(params, &@scope)
    end
  else
    @scope
  end
end