Module: DeadSimpleCMS::Attribute::Type::CollectionSupport

Included in:
Numeric, String
Defined in:
lib/dead_simple_cms/attribute/type/collection_support.rb

Constant Summary collapse

VALID_COLLECTION_INPUT_TYPES =
[:select, :radio].freeze
DEFAULT_COLLECTION_INPUT_TYPE =
:select

Instance Method Summary collapse

Instance Method Details

#collectionObject

Public: For performance and loading reasons, we allow the ability to pass through a collection as a lambda.



19
20
21
# File 'lib/dead_simple_cms/attribute/type/collection_support.rb', line 19

def collection
  @collection.is_a?(Proc) ? @collection.call : @collection
end

#initialize(identifier, options = {}) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/dead_simple_cms/attribute/type/collection_support.rb', line 10

def initialize(identifier, options={})
  if @collection = options[:collection]
    # Pick either the options[:input_type], default_input_type, or the :select. Whichever matches the valid types.
    options[:input_type] = ([options[:input_type], default_input_type, DEFAULT_COLLECTION_INPUT_TYPE] & VALID_COLLECTION_INPUT_TYPES).first
  end
  super
end