Sha256: 30f6bbcb2d724b7a93a916353d41b55cf057cdb2b456db0c380cc7adebce5b07
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 KB
Contents
module GrapeApiary class Parameter attr_reader :route, :name, :settings delegate :route_model, :route_namespace, to: :route delegate :requirement, :type, :documentation, :desc, to: :settings delegate :example, to: :documentation, allow_nil: true def initialize(route, name, options) @route = route @name = name @name = name.scan(/\[(.*)\]/).flatten.first if name.include?('[') @settings = parse_options(options) end def description "#{name} (#{requirement}, #{type}, `#{example}`) ... #{desc}" end private def parse_options(options) options = default_options(options) if options.blank? options[:requirement] = options[:required] ? 'required' : 'optional' Hashie::Mash.new(options) end def default_options(options) model = name.include?('_id') ? name.gsub('_id', '') : route.route_model { required: true, requirement: 'required', type: 'uuid', desc: "the `id` of the `#{model}`", documentation: { example: GrapeApiary::Config.generate_id } } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grape-apiary-0.0.4 | lib/grape-apiary/parameter.rb |
grape-apiary-0.0.3 | lib/grape-apiary/parameter.rb |