class OasContrib::Resolver::Preview

Preview command resolver class

Public Class Methods

new(infile, options) click to toggle source

Initialize @param [String] infile spec file path @param [Array] options command options

# File lib/oas_contrib/resolver/preview.rb, line 10
def initialize(infile, options)
  @infile = infile
  @port = options['port']
end

Public Instance Methods

distribute() click to toggle source

Distribute the command artifacts. @return [Boolean]

# File lib/oas_contrib/resolver/preview.rb, line 27
def distribute
  puts "SwaggerUI listen: http://localhost:#{@port} with: #{@expand_path}"
  `docker run --rm --name oas_contrib_preview_swagger_ui \
  -p #{@port}:8080 -e API_URL=#{@basename} \
  -v #{@expand_path}:/usr/share/nginx/html/#{@basename} swaggerapi/swagger-ui`
  raise 'Preview command needs docker.' unless $?.exitstatus.zero?
  true
end
setup() click to toggle source

Setup the resolver object. @return [Boolean]

# File lib/oas_contrib/resolver/preview.rb, line 17
def setup
  @expand_path = File.expand_path(@infile)
  @basename    = File.basename(@expand_path)
  @infile_ext  = File.extname(@infile)
  file_ext_check
  true
end