Class: ActiveAdmin::SearchableSelect::OptionCollection Private

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

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.

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.



5
6
7
8
9
10
11
12
# 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)
  @additional_payload = options.fetch(:additional_payload, {})
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.



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

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

  results = records.map do |record|
    {
      id: record.id,
      text: display_text(record)
    }.merge(hash_of_additional_payload(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.



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

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.



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

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.



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

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