Module: Datagrid::Filters::SelectOptions

Included in:
DynamicFilter, EnumFilter
Defined in:
lib/datagrid/filters/select_options.rb

Instance Method Summary collapse

Instance Method Details

#include_blankObject


25
26
27
28
29
30
# File 'lib/datagrid/filters/select_options.rb', line 25

def include_blank
  unless prompt
    options.has_key?(:include_blank) ?
      Datagrid::Utils.callable(options[:include_blank]) : !multiple?
  end
end

#promptObject


32
33
34
# File 'lib/datagrid/filters/select_options.rb', line 32

def prompt
  options.has_key?(:prompt) ? Datagrid::Utils.callable(options[:prompt]) : false
end

#select(object) ⇒ Object


2
3
4
5
6
7
8
9
10
11
# File 'lib/datagrid/filters/select_options.rb', line 2

def select(object)
  select = self.options[:select]
  if select.is_a?(Symbol)
    object.send(select)
  elsif select.respond_to?(:call)
    Datagrid::Utils.apply_args(object, &select)
  else
    select
  end
end

#select_values(object) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/datagrid/filters/select_options.rb', line 13

def select_values(object)
  options = select(object)
  groups_used = grouped_choices?(options)
  options.map do |option|
    if groups_used
      option[1].map {|o| option_text_and_value(o)}
    else
      option_text_and_value(option)
    end
  end.map(&:last)
end