class R2OAS::Schema::UI

Attributes

unit_paths_file_path[RW]

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method R2OAS::Base::new
# File lib/r2-oas/schema/ui.rb, line 16
def initialize(options = {})
  super
  @ui = swagger.ui
end

Public Instance Methods

start() click to toggle source
# File lib/r2-oas/schema/ui.rb, line 21
def start
  EM.run do
    container.start
    open_browser
    puts "\nwait for single trap ..."
    signal_trap('INT')
    signal_trap('TERM')
  end
end

Private Instance Methods

container() click to toggle source
Reference

www.tomduffield.com/files/presentations/the-nitty-gritty-of-the-docker-api.pdf

# File lib/r2-oas/schema/ui.rb, line 58
def container
  @container ||= Docker::Container.create(
    'Image' => image,
    'ExposedPorts' => { exposed_port => {} },
    'HostConfig' => {
      'PortBindings' => {
        exposed_port => [{ 'HostPort' => port }]
      },
      'Binds' => ["#{swagger_json}:#{volume}"]
    },
    'Volumes' => { volume => {} }
  )
end
open_browser() click to toggle source
# File lib/r2-oas/schema/ui.rb, line 46
def open_browser
  @browser ||= Watir::Browser.new
  @browser.goto(url)
  wait_for_loaded
end
signal_trap(command) click to toggle source
# File lib/r2-oas/schema/ui.rb, line 36
def signal_trap(command)
  Signal.trap(command) do
    container.stop
    container.remove
    logger.info "container id: #{container.id} removed"

    EM.stop
  end
end
wait_for_loaded() click to toggle source
# File lib/r2-oas/schema/ui.rb, line 52
def wait_for_loaded
  Watir::Wait.until { @browser.body.present? }
end