Class: ActionView::Helpers::AttributeBuilders::Select

Inherits:
Base
  • Object
show all
Defined in:
lib/actionview_attribute_builders/attribute_builders/select.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Base

#object

Instance Method Summary collapse

Constructor Details

#initialize(object_name, method_name, template_object, options, html_options) ⇒ Select

Returns a new instance of Select.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/actionview_attribute_builders/attribute_builders/select.rb', line 7

def initialize(object_name, method_name, template_object, options, html_options)
  @html_options = html_options

  super(object_name, method_name, template_object, options)

  @html_options = @html_options.stringify_keys
  [:required, :multiple, :size].each do |prop|
    @html_options[prop.to_s] = @options.delete(prop) if @options.key?(prop) && !@html_options.key?(prop.to_s)
  end

  add_default_name_and_id(@html_options)
  @html_options["value"] = @options.fetch(:selected) { value() }
end

Instance Method Details

#html_attributesObject



21
22
23
# File 'lib/actionview_attribute_builders/attribute_builders/select.rb', line 21

def html_attributes
  @html_options
end

#optionsObject

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
# File 'lib/actionview_attribute_builders/attribute_builders/select.rb', line 25

def options
  return @options unless placeholder_required?(@html_options)

  raise ArgumentError, "include_blank cannot be false for a required field." if @options[:include_blank] == false
  @options[:include_blank] ||= true unless @options[:prompt]

  @options
end