class Sekken::Importer

Public Class Methods

new(resolver, documents, schemas) click to toggle source
# File lib/sekken/importer.rb, line 7
def initialize(resolver, documents, schemas)
  @logger = Logging.logger[self]

  @resolver = resolver
  @documents = documents
  @schemas = schemas
end

Public Instance Methods

import(location) click to toggle source
# File lib/sekken/importer.rb, line 15
def import(location)
  @import_locations = []

  @logger.info("Resolving WSDL document #{location.inspect}.")
  import_document(location) do |document|
    @documents << document
    @schemas.push(document.schemas)
  end

  # resolve xml schema imports
  import_schemas do |schema_location|
    @logger.info("Resolving XML schema import #{schema_location.inspect}.")

    import_document(schema_location) do |document|
      @schemas.push(document.schemas)
    end
  end
end

Private Instance Methods

absolute_url?(location) click to toggle source
# File lib/sekken/importer.rb, line 72
def absolute_url?(location)
  location =~ Resolver::URL_PATTERN
end
import_document(location, &block) click to toggle source
# File lib/sekken/importer.rb, line 36
def import_document(location, &block)
  if @import_locations.include? location
    @logger.info("Skipping already imported location #{location.inspect}.")
    return
  end

  xml = @resolver.resolve(location)
  @import_locations << location

  document = WSDL::Document.new Nokogiri.XML(xml), @schemas
  block.call(document)

  # resolve wsdl imports
  document.imports.each do |import_location|
    @logger.info("Resolving WSDL import #{import_location.inspect}.")
    import_document(import_location, &block)
  end
end
import_schemas() { |schema_location| ... } click to toggle source
# File lib/sekken/importer.rb, line 55
def import_schemas
  @schemas.each do |schema|
    schema.imports.each do |namespace, schema_location|
      next unless schema_location

      unless absolute_url? schema_location
        @logger.warn("Skipping XML Schema import #{schema_location.inspect}.")
        next
      end

      # TODO: also skip if the schema was already imported

      yield(schema_location)
    end
  end
end