Sha256: b7f604fadf0c1e6635819f111ae222d1cc1ba455c18c729967d1c55e37400b14

Contents?: true

Size: 878 Bytes

Versions: 2

Compression:

Stored size: 878 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.
    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 # rubocop:disable Metrics/MethodLength
      each_value do |v|
        if v.respond_to? :attach_parent
          v.attach_parent self
        elsif v.respond_to? :each_value
          v.each_value do |sv|
            sv.attach_parent self if sv.respond_to? :attach_parent
          end
        elsif 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

2 entries across 2 versions & 1 rubygems

Version Path
swagger-core-0.2.2 lib/swagger/attachable.rb
swagger-core-0.2.1 lib/swagger/attachable.rb