Sha256: ec19fd634dbae234b4fecbfed1feb8e55e217fe3786fcf837f02d7ccca72e285
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true # author: Vadim Shaveiko <@vshaveyko> # :nodoc: class RailsApiDoc::Model::AttributeParser # TODO : Change to I18n. Added on: 08.10.16. Added by: <@vshaveyko> WRONG_NAME_ERROR_STRING = 'Name should consist only of letters\ciphers\underscores' class << self def parse_attributes(params) type = :enum if params[:enum].present? { name: parse_name(params[:name]), type: type || parse_type(params[:type]), enum: parse_enum(params[:enum]) }.compact end private def parse_name(name_string) return if name_string.blank? raise ArgumentError, WRONG_NAME_ERROR_STRING unless name_string =~ /[A-z0-9_]*/ name_string.underscore.to_sym end def parse_enum(enum_string) return if enum_string.blank? enum_string.split(',').map do |enum_value| parse_enum_value(enum_value) end end def parse_enum_value(value) case value when /^\d+$/ value.to_i when 'true' true when 'false' false else value end end def parse_type(type) return if type.blank? type.constantize end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_api_documentation-0.2.3 | lib/rails_api_doc/model/attribute_parser.rb |