module Datagrid::Filters::SelectOptions
Public Instance Methods
include_blank()
click to toggle source
# 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
prompt()
click to toggle source
# File lib/datagrid/filters/select_options.rb, line 32 def prompt options.has_key?(:prompt) ? Datagrid::Utils.callable(options[:prompt]) : false end
select(object)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
grouped_choices?(choices)
click to toggle source
Rails built-in method: github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/actionview/lib/action_view/helpers/tags/select.rb#L36 Code reuse is difficult, so it is easier to duplicate it
# File lib/datagrid/filters/select_options.rb, line 54 def grouped_choices?(choices) !choices.blank? && choices.first.respond_to?(:last) && Array === choices.first.last end
option_text_and_value(option)
click to toggle source
Rails built-in method: github.com/rails/rails/blob/94e80269e36caf7b2d22a7ab68e6898d3a824122/actionview/lib/action_view/helpers/form_options_helper.rb#L789 Code reuse is difficult, so it is easier to duplicate it
# File lib/datagrid/filters/select_options.rb, line 41 def option_text_and_value(option) # Options are [text, value] pairs or strings used for both. if !option.is_a?(String) && option.respond_to?(:first) && option.respond_to?(:last) option = option.reject { |e| Hash === e } if Array === option [option.first, option.last] else [option, option] end end