Sha256: a454e41cb1937dec246d3c6c9bf89d492d8070c202a9d6f973e391b67056b8db

Contents?: true

Size: 869 Bytes

Versions: 14

Compression:

Stored size: 869 Bytes

Contents

module Schemacop
  module V3
    class ObjectNode < Node
      def self.allowed_options
        super + %i[classes strict]
      end

      def self.create(classes, **options, &block)
        options[:classes] = classes
        super(**options, &block)
      end

      def as_json
        {} # Not supported by Json Schema
      end

      protected

      def allowed_types
        Hash[@classes.map { |c| [c, c.name] }]
      end

      def init
        @classes = Array(options.delete(:classes) || [])
        @strict = options.delete(:strict)
        @strict = true if @strict.nil?
      end

      def type_assertion_method
        @strict ? :instance_of? : :is_a?
      end

      def validate_self
        unless @strict.is_a?(TrueClass) || @strict.is_a?(FalseClass)
          fail 'Option "strict" must be a "boolean".'
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
schemacop-3.0.7 lib/schemacop/v3/object_node.rb
schemacop-3.0.6 lib/schemacop/v3/object_node.rb
schemacop-3.0.5 lib/schemacop/v3/object_node.rb
schemacop-3.0.4 lib/schemacop/v3/object_node.rb
schemacop-3.0.3 lib/schemacop/v3/object_node.rb
schemacop-3.0.2 lib/schemacop/v3/object_node.rb
schemacop-3.0.1 lib/schemacop/v3/object_node.rb
schemacop-3.0.0 lib/schemacop/v3/object_node.rb
schemacop-3.0.0.rc5 lib/schemacop/v3/object_node.rb
schemacop-3.0.0.rc4 lib/schemacop/v3/object_node.rb
schemacop-3.0.0.rc3 lib/schemacop/v3/object_node.rb
schemacop-3.0.0.rc2 lib/schemacop/v3/object_node.rb
schemacop-3.0.0.rc1 lib/schemacop/v3/object_node.rb
schemacop-3.0.0.rc0 lib/schemacop/v3/object_node.rb