class SwaggerDocsGenerator::Generator
# Generate JSON file
Create a json file for swagger-ui service
@!attribute [r] swagger_file
@return [String] the swagger file name with path
Attributes
meta[R]
swagger_file[R]
Public Class Methods
new()
click to toggle source
# File lib/swagger_docs_generator/generator.rb, line 13 def initialize @file = 'swagger.json' @swagger_file = File.join(Dir.pwd, 'public', @file) @temp = FileUtils.mkdir_p(SwaggerDocsGenerator.temporary_folder) end
Public Instance Methods
delete_temporary_files()
click to toggle source
Delete files temporary
# File lib/swagger_docs_generator/generator.rb, line 38 def delete_temporary_files FileUtils.rm_rf(@temp[0]) if SwaggerDocsGenerator.configure.cleanning end
generate_swagger_file()
click to toggle source
Open or create a swagger.json file
# File lib/swagger_docs_generator/generator.rb, line 26 def generate_swagger_file delete_file_before File.open(@swagger_file, 'a+') do |file| file.write(if SwaggerDocsGenerator.configure.compress write_in_swagger_file.to_json else JSON.pretty_generate write_in_swagger_file end) end end
import_documentations()
click to toggle source
Import documentation file
# File lib/swagger_docs_generator/generator.rb, line 20 def import_documentations require SwaggerDocsGenerator.file_base SwaggerDocsGenerator.file_docs.each { |rb| require rb } end
info_controller_parser() { |"#{prefix_info} [Controller] #{CONTROLLER}"| ... }
click to toggle source
Create string with controller parsed
# File lib/swagger_docs_generator/generator.rb, line 53 def info_controller_parser klasses = "#{SwaggerDocsGenerator.version_ruby}::BaseDoc".constantize klasses.subclasses.each do |controller| yield("#{prefix_info} [Controller] #{controller::CONTROLLER}") end end
info_swagger_file()
click to toggle source
Create string with info to swagger file path
# File lib/swagger_docs_generator/generator.rb, line 43 def info_swagger_file "#{prefix_info} #{@swagger_file}" end
info_swagger_temporary()
click to toggle source
Create string with info to path temporary file
# File lib/swagger_docs_generator/generator.rb, line 48 def info_swagger_temporary "#{prefix_info} #{SwaggerDocsGenerator.temporary_folder}" end
Private Instance Methods
delete_file_before()
click to toggle source
# File lib/swagger_docs_generator/generator.rb, line 68 def delete_file_before File.delete(@swagger_file) if File.exist?(@swagger_file) end
prefix_info()
click to toggle source
# File lib/swagger_docs_generator/generator.rb, line 64 def prefix_info '->' end
write_in_swagger_file()
click to toggle source
:reek: UtilityFunction
# File lib/swagger_docs_generator/generator.rb, line 73 def write_in_swagger_file # Parse option to this gem hash = MetadataConfiguration.new.construct_swagger_file hash.merge!(MetadataInfo.new.construct_swagger_file) # Parse temporary file (controller - actions) hash.merge!(MetadataJsons.new.construct_swagger_file) # Parse Model hash.merge!(MetadataDefinition.new.construct_swagger_file) end