Sha256: 33b0042b0bded827ab8c3086b1fe179eeea62ca9edb251fb06c7c950c01fdd49
Contents?: true
Size: 1.08 KB
Versions: 20
Compression:
Stored size: 1.08 KB
Contents
# encoding: utf-8 module Hyperdrive class Param attr_reader :name, :description, :required, :type, :constraints def initialize(name, description, options = {}) @name = name.to_s @description = description options = default_options.merge(options) @required = if options[:required] == true %w(POST PUT PATCH) elsif options[:required] == false [] else Array(options[:required]) end @type = options[:type] @constraints = "#{required_constraint} #{options[:constraints]}" end def required?(http_request_method) @required.include? http_request_method end def to_hash { name: @name, description: @description, type: @type, constraints: @constraints } end private def default_options { required: true, type: 'String', constraints: nil } end def required_constraint if @required.empty? '' else "Required for: #{@required.join(', ')}." end end end end
Version data entries
20 entries across 20 versions & 1 rubygems