Sha256: 2ed3081db24dd16ec6f77f821683dad9bbe4474e700553947a70f04b24858b5a

Contents?: true

Size: 1.47 KB

Versions: 23

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

# rubocop:disable Lint/Eval
module SwaggerDocsGenerator
  # # Parse Mongo model
  class ModelMongo
    NAME = :mongo
    TYPES = {
      'Array' =>            { type: 'string' },
      'BigDecimal' =>       { type: 'number', format: 'double' },
      'Mongoid::Boolean' => { type: 'boolean' },
      'Date' =>             { type: 'string', format: 'date' },
      'DateTime' =>         { type: 'string', format: 'date-time' },
      'Float' =>            { type: 'number', format: 'float' },
      'Hash' =>             { type: 'string' },
      'Integer' =>          { type: 'integer', format: 'int64' },
      'BSON::ObjectId' =>   { type: 'string' },
      'Object' =>           { type: 'string' },
      'BSON::Binary' =>     { type: 'string', format: 'binary' },
      'Range' =>            { type: 'string' },
      'String' =>           { type: 'string' },
      'Symbol' =>           { type: 'string' },
      'Time' =>             { type: 'string', format: 'date-time' },
      'TimeWithZone' =>     { type: 'string', format: 'date-time' }
    }.freeze

    def initialize(model)
      @model = eval(model)
    end

    def attribute_properties
      propertie = {}
      @model.fields.each do |name, _value|
        propertie.merge!(attribute_propertie(name))
      end
      propertie
    end

    private

    def attribute_propertie(name)
      {
        name => TYPES.fetch(@model.fields[name].type.to_s)
      }
    end
  end
end
# rubocop:enable Lint/Eval

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
swagger_docs_generator-0.5.1 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.5.0.pre.42 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.4.0 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.6 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.6.pre.34 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.5 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.5.pre.31 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.4.pre.26 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.4 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.4.pre.23 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.3 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.2 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.1 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.0.pre.19 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.3.0.pre.18 lib/swagger_docs_generator/models/mongo.rb
swagger_docs_generator-0.2.0 lib/swagger_docs_generator/parser/models/mongo.rb
swagger_docs_generator-0.2.0.pre.14 lib/swagger_docs_generator/parser/models/mongo.rb
swagger_docs_generator-0.2.0.pre.13 lib/swagger_docs_generator/parser/models/mongo.rb
swagger_docs_generator-0.2.0.pre.12 lib/swagger_docs_generator/parser/models/mongo.rb
swagger_docs_generator-0.2.0.pre.11 lib/swagger_docs_generator/parser/models/mongo.rb