class SwaggerDocsGenerator::ParserDefinition

# Parse Controller classes

Parse controller classes in Rails application. It's create temporary file and adding automaticaly tags element.

Public Class Methods

new(name, &block) click to toggle source
Calls superclass method
# File lib/swagger_docs_generator/parser/definition.rb, line 10
def initialize(name, &block)
  super(binding.of_callers[1].klass)
  @name = name
  instance_eval(&block)
end

Public Instance Methods

adding_definition() click to toggle source
# File lib/swagger_docs_generator/parser/definition.rb, line 16
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 Instance Methods

construct() click to toggle source
# File lib/swagger_docs_generator/parser/definition.rb, line 46
def construct
  {
    type: @type || 'object',
    required: @required || [],
    properties: @properties
  }
end
construct_definition() click to toggle source
# File lib/swagger_docs_generator/parser/definition.rb, line 42
def construct_definition
  { format_name => construct }
end
format_name() click to toggle source
# File lib/swagger_docs_generator/parser/definition.rb, line 54
def format_name
  @name.tr(' ', '_').camelize
end
properties(text = nil, &block) click to toggle source
# File lib/swagger_docs_generator/parser/definition.rb, line 30
def properties(text = nil, &block)
  @properties = if block_given?
                  { @required.first => SubProperties.new(&block).construct }
                else
                  text
                end
end
required(text) click to toggle source
# File lib/swagger_docs_generator/parser/definition.rb, line 38
def required(text)
  @required = text
end
type(text) click to toggle source
# File lib/swagger_docs_generator/parser/definition.rb, line 26
def type(text)
  @type = text
end