Class: SelectableAttrRails::Helpers::CheckBoxGroupHelper::Builder

Inherits:
AbstractSelectionBuilder show all
Defined in:
lib/selectable_attr_rails/helpers/check_box_group_helper.rb

Instance Attribute Summary

Attributes inherited from AbstractSelectionBuilder

#entry_hash

Instance Method Summary collapse

Methods inherited from AbstractSelectionBuilder

#add_class_name, #camelize_keys, #enum_hash_array_from_class, #enum_hash_array_from_object, #tag_id, #update_options

Constructor Details

#initialize(object, object_name, method, options, template) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
10
11
# File 'lib/selectable_attr_rails/helpers/check_box_group_helper.rb', line 6

def initialize(object, object_name, method, options, template)
  super(object, object_name, method, options, template)
  @entry_hash_array ||= enum_hash_array_from_object
  @param_name = "#{@base_name}_ids"
  @check_box_options = @options.delete(:check_box) || {}
end

Instance Method Details

#check_box(options = nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/selectable_attr_rails/helpers/check_box_group_helper.rb', line 22

def check_box(options = nil)
  options = update_options({
      :id => @check_box_id, :type => 'checkbox', :value => @tag_value,
      :name => "#{@object_name}[#{@param_name}][]"
    }, @check_box_options, options)
  options[:checked] = 'checked' if @entry_hash[:select]
  @template.tag("input", options)
end

#each(&block) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/selectable_attr_rails/helpers/check_box_group_helper.rb', line 13

def each(&block)
  @entry_hash_array.each do |entry_hash|
    @entry_hash= entry_hash
    @tag_value = @entry_hash[:id].to_s.gsub(/\s/, "_").gsub(/\W/, "")
    @check_box_id = "#{@object_name}_#{@param_name}_#{@tag_value}"
    yield(self)
  end
end

#label(text = nil, options = nil) ⇒ Object



31
32
33
34
# File 'lib/selectable_attr_rails/helpers/check_box_group_helper.rb', line 31

def label(text = nil, options = nil)
  @template.("label", text || @entry_hash[:name],
    update_options({:for => @check_box_id}, options))
end