Sha256: d50bfd059b09b8f1688a7510beba16d3ba02bc674dfa6ab3cea528e83c6650c0
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
module GrapeApiary class Parameter attr_reader :route, :full_name, :name, :settings delegate :route_model, :namespace, to: :route 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 requirement settings[:requirement] end def type settings[:type] end def desc settings[:desc] end def documentation settings[:documentation] end def example documentation ? documentation[:example] : nil 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' 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-1.0.0 | lib/grape-apiary/parameter.rb |