Sha256: 3e358be8831aa38171f1a86935033b45cd1f8e3740ed84c6ed2a68b8debf05dd

Contents?: true

Size: 674 Bytes

Versions: 27

Compression:

Stored size: 674 Bytes

Contents

module Foobara
  module BuiltinTypes
    module Attributes
      module Casters
        class Hash < Value::Caster
          def applicable?(value)
            value.is_a?(::Hash) && value.keys.all? { |key| key.is_a?(::Symbol) || key.is_a?(::String) }
          end

          def applies_message
            "be a hash with symbolizable keys"
          end

          def cast(hash)
            keys = hash.keys
            non_symbolic_keys = keys.reject { |key| key.is_a?(::Symbol) }

            if non_symbolic_keys.empty?
              hash
            else
              Util.symbolize_keys(hash)
            end
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/builtin_types/src/attributes/casters/hash.rb
foobara-0.0.6 projects/builtin_types/src/attributes/casters/hash.rb
foobara-0.0.5 projects/builtin_types/src/attributes/casters/hash.rb
foobara-0.0.4 projects/builtin_types/src/attributes/casters/hash.rb
foobara-0.0.3 projects/builtin_types/src/attributes/casters/hash.rb
foobara-0.0.2 projects/builtin_types/src/attributes/casters/hash.rb
foobara-0.0.1 projects/builtin_types/src/attributes/casters/hash.rb