Class: Natsuzora::Contract::AST::Record
- 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
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(properties = {}, required = []) ⇒ Record
constructor
A new instance of Record.
- #to_h ⇒ Object
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
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
11 12 13 |
# File 'lib/natsuzora/contract/ast/record.rb', line 11 def properties @properties end |
#required ⇒ Object (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_h ⇒ Object
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 |