Sha256: c68c6d14d0292c5f45eea12eeafbdc46fa92202efe7e3426394544b1a0230e94

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

module Swagger
  # A module that attaches parent objects to their children so you can navigate back
  # up the hierarchy.
  module Attachable
    # The top-level object in the hierarchy.
    attr_accessor :children
    def root
      return self if parent.nil?
      parent.root
    end

    # @api private
    def attach_parent(parent)
      @parent = parent
      attach_to_children
    end

    # @api private
    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
        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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
swagger-parser-0.2.5 lib/swagger/attachable.rb