Class: OasContrib::Resolver::Preview

Inherits:
Base
  • Object
show all
Defined in:
lib/oas_contrib/resolver/preview.rb

Overview

Preview command resolver class

Constant Summary

Constants inherited from Base

Base::DEFINED_FILE_EXT, Base::DIR_NAME_META, Base::DIR_NAME_MODEL, Base::DIR_NAME_PATH

Instance Attribute Summary

Attributes inherited from Base

#data, #spec

Instance Method Summary collapse

Methods inherited from Base

#file_ext_check, #input, #input_dir, #input_lambda, #output, #resolve, #v2?, #v3?

Methods included from Interface::Resolver

#load, #resolve

Constructor Details

#initialize(infile, options) ⇒ Preview

Initialize

Parameters:

  • infile (String)

    spec file path

  • options (Array)

    command options



10
11
12
13
# File 'lib/oas_contrib/resolver/preview.rb', line 10

def initialize(infile, options)
  @infile = infile
  @port = options['port']
end

Instance Method Details

#distributeBoolean

Distribute the command artifacts.

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# 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

#setupBoolean

Setup the resolver object.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# 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