class SimpleForm::Inputs::GroupedCollectionSelectInput
Public Instance Methods
input(wrapper_options = nil)
click to toggle source
# File lib/simple_form/inputs/grouped_collection_select_input.rb, line 4 def input(wrapper_options = nil) label_method, value_method = detect_collection_methods merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) @builder.grouped_collection_select(attribute_name, grouped_collection, group_method, group_label_method, value_method, label_method, input_options, merged_input_options) end
Private Instance Methods
collection()
click to toggle source
Sample collection
# File lib/simple_form/inputs/grouped_collection_select_input.rb, line 24 def collection @collection ||= grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || [] end
detect_method_from_class(collection_classes)
click to toggle source
# File lib/simple_form/inputs/grouped_collection_select_input.rb, line 43 def detect_method_from_class(collection_classes) return {} if collection_classes.empty? sample = collection_classes.first { label: SimpleForm.collection_label_methods.find { |m| sample.instance_methods.include?(m) }, value: SimpleForm.collection_value_methods.find { |m| sample.instance_methods.include?(m) } } end
group_label_method()
click to toggle source
# File lib/simple_form/inputs/grouped_collection_select_input.rb, line 32 def group_label_method label = options.delete(:group_label_method) unless label common_method_for = detect_common_display_methods(detect_collection_classes(grouped_collection)) label = common_method_for[:label] end label end
group_method()
click to toggle source
# File lib/simple_form/inputs/grouped_collection_select_input.rb, line 28 def group_method @group_method ||= options.delete(:group_method) end
grouped_collection()
click to toggle source
# File lib/simple_form/inputs/grouped_collection_select_input.rb, line 16 def grouped_collection @grouped_collection ||= begin grouped_collection = options.delete(:collection) grouped_collection.respond_to?(:call) ? grouped_collection.call : grouped_collection.to_a end end