Sha256: 074b5c86c405f694c30704b254f80c041274a845a0bcff832b7e1daee318677f

Contents?: true

Size: 730 Bytes

Versions: 19

Compression:

Stored size: 730 Bytes

Contents

module Avo
  module Fields
    class BooleanGroupField < BaseField
      attr_reader :options

      def initialize(id, **args, &block)
        super(id, **args, &block)

        @options = args[:options].present? ? args[:options] : {}
      end

      def to_permitted_param
        ["#{id}": []]
      end

      def fill_field(model, key, value)
        new_value = {}

        # Filter out the empty ("") value boolean group generates
        value = value.filter do |arr_value|
          arr_value.present?
        end

        # Cast values to booleans
        options.each do |id, label|
          new_value[id] = value.include? id.to_s
        end

        model[id] = new_value

        model
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
avo-1.6.4.pre.1 lib/avo/fields/boolean_group_field.rb
avo-1.6.3.pre.2 lib/avo/fields/boolean_group_field.rb
avo-1.6.3.pre.1 lib/avo/fields/boolean_group_field.rb
avo-1.6.2.pre.1 lib/avo/fields/boolean_group_field.rb
avo-1.6.1 lib/avo/fields/boolean_group_field.rb
avo-1.6.0 lib/avo/fields/boolean_group_field.rb
avo-1.5.5 lib/avo/fields/boolean_group_field.rb
avo-1.5.4 lib/avo/fields/boolean_group_field.rb
avo-1.5.3 lib/avo/fields/boolean_group_field.rb
avo-1.5.2 lib/avo/fields/boolean_group_field.rb
avo-1.5.1 lib/avo/fields/boolean_group_field.rb
avo-1.5.0 lib/avo/fields/boolean_group_field.rb
avo-1.4.5.pre.1 lib/avo/fields/boolean_group_field.rb
avo-1.4.4.pre.1 lib/avo/fields/boolean_group_field.rb
avo-1.4.4 lib/avo/fields/boolean_group_field.rb
avo-1.4.3 lib/avo/fields/boolean_group_field.rb
avo-1.4.2 lib/avo/fields/boolean_group_field.rb
avo-1.4.1 lib/avo/fields/boolean_group_field.rb
avo-1.4.0 lib/avo/fields/boolean_group_field.rb