Sha256: 7ff17db9fa2f5311d8518ec3ed50d002b325f3c25da9117da4d2bff6c134f10b

Contents?: true

Size: 1.17 KB

Versions: 27

Compression:

Stored size: 1.17 KB

Contents

module SimpleForm
  module Inputs
    class GroupedCollectionSelectInput < CollectionInput
      def input
        label_method, value_method = detect_collection_methods
        @builder.grouped_collection_select(attribute_name, grouped_collection,
                      group_method, group_label_method, value_method, label_method,
                      input_options, input_html_options)
      end

      private

      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

      # Sample collection
      def collection
        @collection ||= grouped_collection.first.try(:send, group_method) || []
      end

      def group_method
        @group_method ||= options.delete(:group_method)
      end

      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
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
simple_form-3.0.4 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-2.1.3 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-2.1.2 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-3.0.3 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-3.0.2 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-3.0.1 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-2.1.1 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-3.0.0 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form_awesome-2.5.0 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form_awesome-2.4.0 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form_awesome-2.3.0 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form_awesome-2.2.0 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-3.0.0.rc lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-2.1.0 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-3.0.0.beta1 lib/simple_form/inputs/grouped_collection_select_input.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.4/lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-2.0.4 lib/simple_form/inputs/grouped_collection_select_input.rb
simple_form-2.0.3 lib/simple_form/inputs/grouped_collection_select_input.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/lib/simple_form/inputs/grouped_collection_select_input.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/lib/simple_form/inputs/grouped_collection_select_input.rb