Sha256: b6bfc69049e06b9fafb57aa7ea1936823788249433a70996d4d77ac124f77801
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal:true require 'fileutils' # Scope Rails module R2OAS module Deploy class Client < Schema::Base def deploy copy_swagger_ui_dist copy_swagger_ui_index copy_oas_doc_file end private def copy_swagger_ui_dist docs_path = File.expand_path(Rails.root.join(deploy_dir_path), __FILE__) return if FileTest.exists?(docs_path) FileUtils.mkdir_p(docs_path) unless FileTest.exists?(docs_path) dist_path = File.expand_path('swagger-ui/dist', __dir__) FileUtils.cp_r(dist_path, docs_path) end 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 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("#{root_dir_path}/#{doc_save_file_name}") FileUtils.cp_r(oas_doc_file_path, swagger_file_path) end # [ref] # https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ErbNewArguments 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
r2-oas-0.3.1 | lib/r2-oas/deploy/client.rb |
r2-oas-0.3.0 | lib/r2-oas/deploy/client.rb |