Sha256: cc39f6db58dca4a1fc9468d8ba71cc2b86c567c4fb15339a642ea8805bb915ca

Contents?: true

Size: 520 Bytes

Versions: 1

Compression:

Stored size: 520 Bytes

Contents

# frozen_string_literal: true

module Granite
  module Form
    module Types
      class Dictionary < HasSubtype
        def prepare(value)
          value = to_hash(value)
          value = value.stringify_keys.slice(*reflection.keys) if reflection.keys.present?
          value.transform_values { |v| subtype_definition.prepare(v) }.with_indifferent_access
        end

        private

        def to_hash(value)
          Hash[value]
        rescue ArgumentError
          {}
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
granite-form-0.6.0 lib/granite/form/types/dictionary.rb