Class: Swaggard::Parsers::Models

Inherits:
Object
  • Object
show all
Defined in:
lib/swaggard/parsers/models.rb

Instance Method Summary collapse

Instance Method Details

#parse_yard_object(yard_object) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/swaggard/parsers/models.rb', line 20

def parse_yard_object(yard_object)
  return unless yard_object.type == :class

  Swagger::Definition.new(yard_object.path, ancestors: yard_object.inheritance_tree.map(&:path)).tap do |definition|
    yard_object.tags.each do |tag|
      case tag.tag_name
      when 'attr'
        property = Swaggard::Parsers::Property.run(tag)
        definition.add_property(property)
      when 'ignore_inherited'
        definition.ignore_inherited = true
      end
    end
  end
end

#run(yard_objects) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/swaggard/parsers/models.rb', line 8

def run(yard_objects)
  definitions = {}

  yard_objects.each do |yard_object|
    definition = parse_yard_object(yard_object)

    definitions[definition.id] = definition if definition
  end

  definitions
end