Class: Jsapi::Meta::Schema::Wrapper

Inherits:
Model::Wrapper show all
Defined in:
lib/jsapi/meta/schema/wrapper.rb

Direct Known Subclasses

Array::Wrapper, Object::Wrapper

Instance Attribute Summary collapse

Attributes inherited from Model::Wrapper

#definitions

Instance Method Summary collapse

Methods inherited from Model::Wrapper

#==, #inspect

Constructor Details

#initialize(schema, definitions) ⇒ Wrapper

Returns a new instance of Wrapper.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jsapi/meta/schema/wrapper.rb', line 10

def initialize(schema, definitions)
  @existence =
    [schema.existence].tap do |levels|
      s = schema
      while s.is_a?(Reference)
        s = s.resolve(definitions, deep: false)
        levels << s.existence
      end
    end.compact.max || Existence::ALLOW_OMITTED
  super
end

Instance Attribute Details

#existenceObject (readonly)

The level of existence.



8
9
10
# File 'lib/jsapi/meta/schema/wrapper.rb', line 8

def existence
  @existence
end

Instance Method Details

#default_value(context: nil) ⇒ Object

Returns the default value within context.



23
24
25
26
27
# File 'lib/jsapi/meta/schema/wrapper.rb', line 23

def default_value(context: nil)
  return default unless default.nil?

  definitions.default_value(type, context: context)
end