Sha256: f29f934cfc608d3df9b97f07f68b3054ecdca2acfe5cb8e71890b407affa2c53

Contents?: true

Size: 722 Bytes

Versions: 10

Compression:

Stored size: 722 Bytes

Contents

module ActiveData
  module Model
    module Attributes
      class Dictionary < Attribute
        delegate :keys, to: :reflection

        def read
          @value ||= begin
            hash = read_before_type_cast
            hash = hash.stringify_keys.slice(*keys) if keys.present?

            normalize(Hash[hash.map do |key, value|
              [key, enumerize(typecast(value))]
            end].with_indifferent_access).with_indifferent_access
          end
        end

        def read_before_type_cast
          @value_before_type_cast ||= Hash[(@value_cache.presence || {}).map do |key, value|
            [key, defaultize(value)]
          end].with_indifferent_access
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active_data-1.2.0 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.7 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.6 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.5 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.4 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.3 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.2 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.1 lib/active_data/model/attributes/dictionary.rb
active_data-1.1.0 lib/active_data/model/attributes/dictionary.rb
active_data-1.0.0 lib/active_data/model/attributes/dictionary.rb