Sha256: 9b19bfe31b9e7e6b73f1812e8d8fb2c225fd0acc2cf33a602e44c669c32a759b
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module GrapeApiary class Parameter attr_reader :route, :full_name, :name, :settings delegate :route_model, :namespace, to: :route delegate :requirement, :type, :documentation, :desc, to: :settings delegate :example, to: :documentation, allow_nil: true def initialize(route, name, options) @full_name = name @name = name @name = name.scan(/\[(.*)\]/).flatten.first if name.include?('[') @route = route @settings = parse_options(options) end def description "#{name} (#{requirement}, #{type}, `#{example}`) ... #{desc}" end private def parse_options(options) options = default_options if options.blank? options[:requirement] = options[:required] ? 'required' : 'optional' Hashie::Mash.new(options) end def default_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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grape-apiary-0.2.0 | lib/grape-apiary/parameter.rb |