Module: Betterdocs::Dsl::JsonTypeMapper
- Defined in:
- lib/betterdocs/dsl/json_type_mapper.rb
Class Method Summary collapse
Class Method Details
.derive_json_type_from(klass) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/betterdocs/dsl/json_type_mapper.rb', line 4 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 } or raise TypeError, "Invalid type #{klass} encountered. Use a type that can be mapped to JSON instead." end |
.map_types(types) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/betterdocs/dsl/json_type_mapper.rb', line 19 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 |