Sha256: c5c773ac18b26fc59d52c8679ece20f7344277a32fff732305b2324079f9c9e3

Contents?: true

Size: 675 Bytes

Versions: 22

Compression:

Stored size: 675 Bytes

Contents

# frozen_string_literal: true

module Hako
  module Schema
    class Structure
      def initialize
        @members = {}
      end

      def valid?(object)
        unless object.is_a?(::Hash)
          return false
        end

        @members.each do |key, val_schema|
          unless val_schema.valid?(object[key])
            return false
          end
        end
        true
      end

      def same?(x, y)
        @members.each do |key, val_schema|
          unless val_schema.same?(x[key], y[key])
            return false
          end
        end
        true
      end

      def member(key, schema)
        @members[key] = schema
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hako-2.4.0 lib/hako/schema/structure.rb
hako-2.3.1 lib/hako/schema/structure.rb