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.17.0 lib/hako/schema/structure.rb
hako-2.16.0 lib/hako/schema/structure.rb
hako-2.15.1 lib/hako/schema/structure.rb
hako-2.15.0 lib/hako/schema/structure.rb
hako-2.14.0 lib/hako/schema/structure.rb
hako-2.13.0 lib/hako/schema/structure.rb
hako-2.12.0 lib/hako/schema/structure.rb
hako-2.11.1 lib/hako/schema/structure.rb
hako-2.11.0 lib/hako/schema/structure.rb
hako-2.10.0 lib/hako/schema/structure.rb
hako-2.9.2 lib/hako/schema/structure.rb
hako-2.9.1 lib/hako/schema/structure.rb
hako-2.9.0 lib/hako/schema/structure.rb
hako-2.8.0 lib/hako/schema/structure.rb
hako-2.7.0 lib/hako/schema/structure.rb
hako-2.6.2 lib/hako/schema/structure.rb
hako-2.6.1 lib/hako/schema/structure.rb
hako-2.6.0 lib/hako/schema/structure.rb
hako-2.5.1 lib/hako/schema/structure.rb
hako-2.5.0 lib/hako/schema/structure.rb