Sha256: bbd6a115e622a0f6fbfc31e13a34cbcdedc12d502371ad024ce2b51803c96d7b

Contents?: true

Size: 1.4 KB

Versions: 23

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

# rubocop:disable Lint/Eval
module SwaggerDocsGenerator
  # # Parse Active Record model
  class ModelActiveRecord
    NAME = :active_record
    TYPES = {
      'binary' =>       { type: 'string', format: 'binary' },
      'boolean' =>      { type: 'boolean' },
      'date' =>         { type: 'string', format: 'date' },
      'datetime' =>     { type: 'string', format: 'date-time' },
      'decimal' =>      { type: 'number', format: 'double' },
      'float' =>        { type: 'number', format: 'float' },
      'integer' =>      { type: 'integer', format: 'int32' },
      'bigint' =>       { type: 'integer', format: 'int64' },
      'primary_key' =>  { type: 'integer', format: 'int32' },
      'references' =>   { type: 'integer', format: 'int32' },
      'string' =>       { type: 'string' },
      'text' =>         { type: 'string' },
      'time' =>         { type: 'string', format: 'date-time' },
      'timestamp' =>    { type: 'string', format: 'date-time' }
    }.freeze

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

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

    private

    def attribute_propertie(name)
      {
        name => TYPES[@model.columns_hash[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/active_record.rb
swagger_docs_generator-0.5.0.pre.42 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.4.0 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.6 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.6.pre.34 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.5 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.5.pre.31 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.4.pre.26 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.4 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.4.pre.23 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.3 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.2 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.1 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.0.pre.19 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.3.0.pre.18 lib/swagger_docs_generator/models/active_record.rb
swagger_docs_generator-0.2.0 lib/swagger_docs_generator/parser/models/active_record.rb
swagger_docs_generator-0.2.0.pre.14 lib/swagger_docs_generator/parser/models/active_record.rb
swagger_docs_generator-0.2.0.pre.13 lib/swagger_docs_generator/parser/models/active_record.rb
swagger_docs_generator-0.2.0.pre.12 lib/swagger_docs_generator/parser/models/active_record.rb
swagger_docs_generator-0.2.0.pre.11 lib/swagger_docs_generator/parser/models/active_record.rb