module Formular::Element::Modules::Checkable::InstanceMethods
Public Instance Methods
collection()
click to toggle source
# File lib/formular/element/modules/checkable.rb, line 49 def collection unless collection? options[:label_options] = options[:control_label_options] return [self] end base_options = collection_base_options @collection ||= options[:collection].map do |item| opts = base_options.dup opts[:value] = item.send(options[:value_method]) opts[:label] = item.send(options[:label_method]) opts[:id] = if options[:id] "#{options[:id]}_#{opts[:value]}" else "#{attribute_name || options[:name].gsub('[]', '')}_#{opts[:value]}" end self.class.(opts) end end
collection?()
click to toggle source
# File lib/formular/element/modules/checkable.rb, line 72 def collection? options[:collection] end
group_label()
click to toggle source
# File lib/formular/element/modules/checkable.rb, line 38 def group_label return '' unless has_group_label? label_opts = label_options.dup label_opts[:content] = label_text builder.checkable_group_label(label_opts).to_s end
has_group_label?()
click to toggle source
# File lib/formular/element/modules/checkable.rb, line 45 def has_group_label? collection.size > 1 && has_label? end
Private Instance Methods
collection_base_options()
click to toggle source
# File lib/formular/element/modules/checkable.rb, line 81 def collection_base_options opts = attributes.select { |k, v| ![:name, :id, :checked, :class].include?(k) } # FIXME due to class merging, we'll end up with duplicate classes... opts[:attribute_name] = attribute_name if attribute_name opts[:builder] = builder if builder opts[:label_options] = options[:control_label_options] if options[:control_label_options] opts[:name] = options[:name] if options[:name] # do we need this?? opts end
is_checked?()
click to toggle source
# File lib/formular/element/modules/checkable.rb, line 77 def is_checked? !options[:checked].nil? || reader_value == options[:value] end