Sha256: f3fc88f59a57b59d2b2265fdf58a7a4e0a903cac9dded6fcc44cd1040c64884e

Contents?: true

Size: 983 Bytes

Versions: 1

Compression:

Stored size: 983 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(controller, description)
      super(controller)
      prepare_file
      @description = description
    end

    def adding_tag
      json = JSON.parse(File.read(controller_file))
      File.open(controller_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: {} }
      File.open(controller_file, 'a+') { |file| file.puts(base_file.to_json) }
    end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
swagger_docs_generator-0.2.0.pre.12 lib/swagger_docs_generator/parser/controller.rb