Sha256: 7f01c1f63fedb04f7ad24139090b9e0132a47cb76d388a5c70b2d494caa9da8d

Contents?: true

Size: 662 Bytes

Versions: 11

Compression:

Stored size: 662 Bytes

Contents

module Betterdocs::Dsl::JsonTypeMapper
  module_function

  def derive_json_type_from(klass)
    Class === klass or klass = klass.class
    {
      TrueClass  => 'boolean',
      FalseClass => 'boolean',
      NilClass   => 'null',
      Numeric    => 'number',
      Array      => 'array',
      Hash       => 'object',
      String     => 'string',
    }.find { |match_class, json_type|
      match_class >= klass and break json_type
    } || 'undefined'
  end

  def map_types(types)
    if Array === types and types.empty?
      types = [ types ]
    else
      types = Array(types)
    end
    types.map { |t| derive_json_type_from(t) }.uniq.sort
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
betterdocs-0.7.0 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.8 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.7 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.6 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.5 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.4 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.3 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.2 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.1 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.6.0 lib/betterdocs/dsl/json_type_mapper.rb
betterdocs-0.5.0 lib/betterdocs/dsl/json_type_mapper.rb