Sha256: 7505aed35ed0ba5131901746cc6122d8ea630cc25be0f64b8e9c7c6ea94c0e75

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

# :reek:InstanceVariableAssumption
module SwaggerDocsGenerator
  # # Parse Controller classes
  #
  # Parse controller classes in Rails application. It's create temporary file
  # and adding automaticaly tags element.
  class ParserDefinition < Parser
    def initialize(name, &block)
      super(binding.of_callers[1].klass)
      @name = name
      instance_eval(&block)
    end

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

    private

    def type(text)
      @type = text
    end

    def properties(text)
      @properties = text
    end

    def required(text)
      @required = text
    end

    def construct_definition
      { format_name => construct }
    end

    def construct
      {
        type: @type || 'object',
        required: @required || [],
        properties: @properties
      }
    end

    def format_name
      @name.tr(' ', '_').camelize
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
swagger_docs_generator-0.3.6 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.6.pre.34 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.5 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.5.pre.31 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.4.pre.26 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.4 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.4.pre.23 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.3 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.2 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.1 lib/swagger_docs_generator/parser/definition.rb
swagger_docs_generator-0.3.0.pre.19 lib/swagger_docs_generator/parser/definition.rb