Class: Natsuzora::Contract::AST::Record

Inherits:
Node
  • Object
show all
Defined in:
lib/natsuzora/contract/ast/record.rb

Overview

Record-style object with named properties. Serialized as ‘kind’ => ‘object’ for JSON compatibility.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}, required = []) ⇒ Record

Returns a new instance of Record.



13
14
15
16
17
# File 'lib/natsuzora/contract/ast/record.rb', line 13

def initialize(properties = {}, required = [])
  super()
  @properties = properties
  @required = required
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



11
12
13
# File 'lib/natsuzora/contract/ast/record.rb', line 11

def properties
  @properties
end

#requiredObject (readonly)

Returns the value of attribute required.



11
12
13
# File 'lib/natsuzora/contract/ast/record.rb', line 11

def required
  @required
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
28
29
# File 'lib/natsuzora/contract/ast/record.rb', line 25

def ==(other)
  other.is_a?(Record) &&
    other.properties == @properties &&
    other.required == @required
end

#to_hObject



19
20
21
22
23
# File 'lib/natsuzora/contract/ast/record.rb', line 19

def to_h
  h = { 'kind' => 'object', 'properties' => @properties.transform_values(&:to_h) }
  h['required'] = @required unless @required.empty?
  h
end