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

Version Path
hyperdrive-0.0.25 lib/hyperdrive/param.rb
hyperdrive-0.0.24 lib/hyperdrive/param.rb
hyperdrive-0.0.23 lib/hyperdrive/param.rb
hyperdrive-0.0.22 lib/hyperdrive/param.rb
hyperdrive-0.0.21 lib/hyperdrive/param.rb
hyperdrive-0.0.20 lib/hyperdrive/param.rb
hyperdrive-0.0.19 lib/hyperdrive/param.rb
hyperdrive-0.0.18 lib/hyperdrive/param.rb
hyperdrive-0.0.17 lib/hyperdrive/param.rb
hyperdrive-0.0.16 lib/hyperdrive/param.rb
hyperdrive-0.0.15 lib/hyperdrive/param.rb
hyperdrive-0.0.14 lib/hyperdrive/param.rb
hyperdrive-0.0.13 lib/hyperdrive/param.rb
hyperdrive-0.0.12 lib/hyperdrive/param.rb
hyperdrive-0.0.11 lib/hyperdrive/param.rb
hyperdrive-0.0.10 lib/hyperdrive/param.rb
hyperdrive-0.0.9 lib/hyperdrive/param.rb
hyperdrive-0.0.8 lib/hyperdrive/param.rb
hyperdrive-0.0.7 lib/hyperdrive/param.rb
hyperdrive-0.0.6 lib/hyperdrive/param.rb