Module: Swagger::Attachable

Included in:
Schema, SwaggerObject
Defined in:
lib/swagger/attachable.rb

Overview

A module that attaches parent objects to their children so you can navigate back up the hierarchy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

The top-level object in the hierarchy.



6
7
8
# File 'lib/swagger/attachable.rb', line 6

def children
  @children
end

Instance Method Details

#attach_parent(parent) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
# File 'lib/swagger/attachable.rb', line 13

def attach_parent(parent)
  @parent = parent
  attach_to_children
end

#attach_to_childrenObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/swagger/attachable.rb', line 19

def attach_to_children
  @children ||= []
  each_value do |v| # rubocop:disable Style/Next
    if v.respond_to? :attach_parent
      v.attach_parent self
      self.children << v
      self.children.uniq!
    end
    if v.respond_to? :each_value
      v.each_value do |sv|
        sv.attach_parent self if sv.respond_to? :attach_parent
      end
    end
    if v.respond_to? :each
      v.each do |sv|
        sv.attach_parent self if sv.respond_to? :attach_parent
      end
    end
  end
end

#rootObject



7
8
9
10
# File 'lib/swagger/attachable.rb', line 7

def root
  return self if parent.nil?
  parent.root
end