class R2OAS::Deploy::Client

Constants

SWAGGER_UI_DIST_URL

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method R2OAS::Base::new
# File lib/r2-oas/deploy/client.rb, line 11
def initialize(options = {})
  super(options)
  @download_dir = "#{SecureRandom.uuid[0..7]}/dist"
  @dist_path = File.expand_path(Rails.root.join(@download_dir), __FILE__)
end

Public Instance Methods

deploy() click to toggle source
# File lib/r2-oas/deploy/client.rb, line 21
def deploy
  copy_swagger_ui_dist
  copy_swagger_ui_index
  copy_oas_doc_file
ensure
  remove_download_dist
end
download_swagger_ui_dist() click to toggle source
# File lib/r2-oas/deploy/client.rb, line 17
def download_swagger_ui_dist
  system("svn export #{SWAGGER_UI_DIST_URL} #{@dist_path}")
end

Private Instance Methods

copy_oas_doc_file() click to toggle source
# File lib/r2-oas/deploy/client.rb, line 47
def copy_oas_doc_file
  swagger_file_path = File.expand_path(Rails.root.join(deploy_dir_path, doc_save_file_name), __FILE__)
  oas_doc_file_path = File.expand_path(output_path)
  FileUtils.cp_r(oas_doc_file_path, swagger_file_path)
end
copy_swagger_ui_dist() click to toggle source
# File lib/r2-oas/deploy/client.rb, line 31
def copy_swagger_ui_dist
  docs_path = File.expand_path(Rails.root.join(deploy_dir_path), __FILE__)
  FileUtils.mkdir_p(docs_path) unless FileTest.exists?(docs_path)
  FileUtils.mkdir_p(@dist_path) unless FileTest.exists?(@dist_path)
  FileUtils.cp_r(@dist_path, docs_path)
end
copy_swagger_ui_index() click to toggle source
# File lib/r2-oas/deploy/client.rb, line 38
def copy_swagger_ui_index
  index_path = File.expand_path(Rails.root.join(deploy_dir_path, 'index.html'), __FILE__)
  @schema_file_path = doc_save_file_name
  template_path = File.expand_path('swagger-ui/index.html.erb', __dir__)
  template = File.read(template_path)
  index = make_index(template)
  File.write(index_path, index)
end
make_index(template) click to toggle source
ref

www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ErbNewArguments

# File lib/r2-oas/deploy/client.rb, line 59
def make_index(template)
  if RUBY_VERSION >= '2.6'
    ERB.new(template, trim_mode: '%').result(binding)
  else
    # rubocop:disable Lint/ErbNewArguments
    ERB.new(template, nil, trim_mode: '%').result(binding)
    # rubocop:enable Lint/ErbNewArguments
  end
end
remove_download_dist() click to toggle source
# File lib/r2-oas/deploy/client.rb, line 53
def remove_download_dist
  FileUtils.rm_rf(File.expand_path('..', @dist_path))
end