Sha256: 26e9b5e543af569521b8daa0cb9c99b9a876c98a7f4c8accaef26b46bdb397a7

Contents?: true

Size: 993 Bytes

Versions: 15

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

module SwaggerDocsGenerator
  # # Parse Controller classes
  #
  # Parse controller classes in Rails application. It's create temporary file
  # and adding automaticaly tags element.
  class ParserController < Parser
    def initialize(description)
      super(binding.of_callers[1].klass)
      @description = description
      prepare_file
    end

    def adding_tag
      json = JSON.parse(File.read(temporary_file))
      File.open(temporary_file, 'w') do |file|
        json['tags'].merge!(construct_tags)
        file.puts(JSON.pretty_generate(json))
      end
    end

    private

    def prepare_file
      delete_file
      base_file = { paths: {}, tags: {}, definitions: {} }
      File.open(temporary_file, 'a+') { |file| file.puts(base_file.to_json) }
    end

    def delete_file
      File.delete(temporary_file) if File.exist?(temporary_file)
    end

    def construct_tags
      { name: tag_name, description: @description }
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
swagger_docs_generator-0.5.1 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.5.0.pre.42 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.4.0 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.6 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.6.pre.34 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.5 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.5.pre.31 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.4.pre.26 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.4 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.4.pre.23 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.3 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.2 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.1 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.0.pre.19 lib/swagger_docs_generator/parser/controller.rb
swagger_docs_generator-0.3.0.pre.18 lib/swagger_docs_generator/parser/controller.rb