Class: OasParser::Property

Inherits:
Object
  • Object
show all
Includes:
RawAccessor
Defined in:
lib/oas_parser/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RawAccessor

included, #method_missing, #respond_to_missing?

Constructor Details

#initialize(owner, schema, name, raw) ⇒ Property

Returns a new instance of Property.



9
10
11
12
13
14
# File 'lib/oas_parser/property.rb', line 9

def initialize(owner, schema, name, raw)
  @owner = owner
  @name = name
  @schema = schema
  @raw = raw
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OasParser::RawAccessor

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/oas_parser/property.rb', line 7

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



7
8
9
# File 'lib/oas_parser/property.rb', line 7

def owner
  @owner
end

#rawObject

Returns the value of attribute raw.



7
8
9
# File 'lib/oas_parser/property.rb', line 7

def raw
  @raw
end

#schemaObject

Returns the value of attribute schema.



7
8
9
# File 'lib/oas_parser/property.rb', line 7

def schema
  @schema
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/oas_parser/property.rb', line 22

def array?
  type == 'array'
end

#collection?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/oas_parser/property.rb', line 30

def collection?
  array? || object?
end

#convert_property_schema_to_properties(schema) ⇒ Object



40
41
42
43
44
45
# File 'lib/oas_parser/property.rb', line 40

def convert_property_schema_to_properties(schema)
  schema = schema['properties'] if schema['properties']
  schema.map do |name, definition|
    OasParser::Property.new(self, raw, name, definition)
  end
end

#object?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/oas_parser/property.rb', line 26

def object?
  type == 'object'
end

#propertiesObject



34
35
36
37
38
# File 'lib/oas_parser/property.rb', line 34

def properties
  return convert_property_schema_to_properties(raw['properties']) if object?
  return convert_property_schema_to_properties(items) if array?
  nil
end

#requiredObject



16
17
18
19
20
# File 'lib/oas_parser/property.rb', line 16

def required
  return true if raw['required']
  return false unless schema['required']
  schema['required'].include? name
end