Sha256: 2466ec1a588e0b3217d9ee2e7ed581fdf5f6de9a84a9f0ea78fe09fedfeea162

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require 'administrate/field/base'

module Administrate
  module Field
    class CollectionSelect < Base
      class Engine < ::Rails::Engine
      end

      def to_s
        @show_text ||= options.fetch(:show_text, data)
      end

      def selectable_ids
        ids
      end

      def selectable_collection
        collection
      end

      def selectable_value
        value_method
      end

      def selectable_text
        text_method
      end

      def selectable_options
        options_method
      end

      def multiple
        multiple_method
      end

      def label
        @label ||= options.fetch(:label, attribute)
      end

      private

      def ids
        @ids ||= options.fetch(:ids, nil)
      end

      def collection
        @collection ||= options.fetch(:collection, proc { [] })
      end

      def value_method
        @value_method ||= options.fetch(:value_method, nil)
      end

      def text_method
        @text_method ||= options.fetch(:text_method, nil)
      end

      def options_method
        @options_method ||= options.fetch(:options, nil)
      end

      def multiple_method
        @multiple_method ||= options.fetch(:multiple, nil)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
administrate-field-collection_select-0.4.0 lib/administrate/field/collection_select.rb
administrate-field-collection_select-0.3.0 lib/administrate/field/collection_select.rb