source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/values_validator.rb | Ruby | mit | 9,984 | master | 1,946 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class ValuesValidator < Base
default_message_key :values
def initialize(attrs, options, required, scope, opts)
super
values = option_value
# Zero-arity procs return a collection p... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/presence_validator.rb | Ruby | mit | 9,984 | master | 355 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class PresenceValidator < Base
default_message_key :presence
def validate_param!(attr_name, params)
return if hash_like?(params) && params.key?(attr_name)
validation_error!(attr_name)
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/at_least_one_of_validator.rb | Ruby | mit | 9,984 | master | 450 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class AtLeastOneOfValidator < MultipleParamsBase
default_message_key :at_least_one
def validate_params!(params)
known_keys = all_keys
return if hash_like?(params) && known_keys.intersect?(pa... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/as_validator.rb | Ruby | mit | 9,984 | master | 361 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class AsValidator < Base
# We use a validator for renaming parameters. This is just a marker for
# the parameter scope to handle the renaming. No actual validation
# happens here.
def validate_pa... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/exactly_one_of_validator.rb | Ruby | mit | 9,984 | master | 730 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class ExactlyOneOfValidator < MultipleParamsBase
def initialize(attrs, options, required, scope, opts)
super
@exactly_one_exception_message = message(:exactly_one)
@mutual_exclusion_excepti... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/multiple_params_base.rb | Ruby | mit | 9,984 | master | 913 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class MultipleParamsBase < Base
def validate!(params)
attributes = MultipleAttributesIterator.new(@attrs, @scope, params)
array_errors = []
attributes.each do |resource_params|
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/coerce_validator.rb | Ruby | mit | 9,984 | master | 1,789 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class CoerceValidator < Base
default_message_key :coerce
def initialize(attrs, options, required, scope, opts)
super
raw_type = @options[:type]
type = hash_like?(raw_type) ? raw_t... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/regexp_validator.rb | Ruby | mit | 9,984 | master | 593 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class RegexpValidator < Base
default_message_key :regexp
def initialize(attrs, options, required, scope, opts)
super
@value = option_value
end
def validate_param!(attr_name,... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/default_validator.rb | Ruby | mit | 9,984 | master | 957 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class DefaultValidator < Base
def initialize(attrs, options, required, scope, opts)
super
# !important, lazy call at runtime
@default_call =
if @options.is_a?(Proc)
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/contract_scope_validator.rb | Ruby | mit | 9,984 | master | 1,198 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class ContractScopeValidator
attr_reader :schema
def initialize(schema:)
@schema = schema
freeze
end
# Validates a given request.
# @param request [Grape::Request] t... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/allow_blank_validator.rb | Ruby | mit | 9,984 | master | 559 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class AllowBlankValidator < Base
default_message_key :blank
def initialize(attrs, options, required, scope, opts)
super
@value = option_value
end
def validate_param!(attr_na... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/length_validator.rb | Ruby | mit | 9,984 | master | 1,617 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class LengthValidator < Base
def initialize(attrs, options, required, scope, opts)
super
@min, @max, @is = @options.values_at(:min, :max, :is)
validate_boundary!(:min, @min)
vali... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/mutually_exclusive_validator.rb | Ruby | mit | 9,984 | master | 383 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class MutuallyExclusiveValidator < MultipleParamsBase
default_message_key :mutual_exclusion
def validate_params!(params)
keys = keys_in_common(params)
return if keys.length <= 1
v... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/validators/except_values_validator.rb | Ruby | mit | 9,984 | master | 1,188 | # frozen_string_literal: true
module Grape
module Validations
module Validators
class ExceptValuesValidator < Base
default_message_key :except_values
def initialize(attrs, options, required, scope, opts)
super
except = option_value
except_proc = except.is_a?(P... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/variant_collection_coercer.rb | Ruby | mit | 9,984 | master | 1,888 | # frozen_string_literal: true
module Grape
module Validations
module Types
# This class wraps {MultipleTypeCoercer}, for use with collections
# that allow members of more than one type.
class VariantCollectionCoercer
# Construct a new coercer that will attempt to coerce
# a list... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/invalid_value.rb | Ruby | mit | 9,984 | master | 415 | # frozen_string_literal: true
module Grape
module Validations
module Types
# Instances of this class may be used as tokens to denote that a parameter value could not be
# coerced. The given message will be used as a validation error.
class InvalidValue
attr_reader :message
def ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/multiple_type_coercer.rb | Ruby | mit | 9,984 | master | 2,187 | # frozen_string_literal: true
module Grape
module Validations
module Types
# This class is intended for use with Grape endpoint parameters that
# have been declared to be of variant-type using the +:types+ option.
# +MultipleTypeCoercer+ will build a coercer for each type declared
# in th... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/custom_type_collection_coercer.rb | Ruby | mit | 9,984 | master | 2,130 | # frozen_string_literal: true
module Grape
module Validations
module Types
# See {CustomTypeCoercer} for details on types
# that will be supported by this by this coercer.
# This coercer works in the same way as +CustomTypeCoercer+
# except that it expects to receive an array of strings t... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/primitive_coercer.rb | Ruby | mit | 9,984 | master | 1,471 | # frozen_string_literal: true
module Grape
module Validations
module Types
# Coerces the given value to a type defined via a +type+ argument during
# initialization. When +strict+ is true, it doesn't coerce a value but check
# that it has the proper type.
class PrimitiveCoercer < DryTypeC... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/json.rb | Ruby | mit | 9,984 | master | 2,277 | # frozen_string_literal: true
module Grape
module Validations
module Types
# Handles coercion and type checking for parameters that are complex
# types given as JSON-encoded strings. It accepts both JSON objects
# and arrays of objects, and will coerce the input to a +Hash+
# or +Array+ o... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/dry_type_coercer.rb | Ruby | mit | 9,984 | master | 1,752 | # frozen_string_literal: true
module Grape
module Validations
module Types
# A base class for classes which must identify a coercer to be used.
# If the +strict+ argument is true, it won't coerce the given value
# but check its type. More information there
# https://dry-rb.org/gems/dry-ty... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/set_coercer.rb | Ruby | mit | 9,984 | master | 788 | # frozen_string_literal: true
module Grape
module Validations
module Types
# Takes the given array and converts it to a set. Every element of the set
# is also coerced.
class SetCoercer < ArrayCoercer
def initialize(type, strict: false)
super
@coercer = nil
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/custom_type_coercer.rb | Ruby | mit | 9,984 | master | 5,970 | # frozen_string_literal: true
module Grape
module Validations
module Types
# This class will detect type classes that implement
# a class-level +parse+ method. The method should accept one
# +String+ argument and should return the value coerced to
# the appropriate type. The method may ra... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/array_coercer.rb | Ruby | mit | 9,984 | master | 1,737 | # frozen_string_literal: true
module Grape
module Validations
module Types
# Coerces elements in an array. It might be an array of strings or integers or
# an array of arrays of integers.
#
# It could've been possible to use an +of+
# method (https://dry-rb.org/gems/dry-types/main/a... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/validations/types/file.rb | Ruby | mit | 9,984 | master | 961 | # frozen_string_literal: true
module Grape
module Validations
module Types
# Implementation for parameters that are multipart file objects.
# Actual handling of these objects is provided by +Rack::Request+;
# this class is here only to assert that rack's handling has succeeded.
class File... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/stack.rb | Ruby | mit | 9,984 | master | 3,193 | # frozen_string_literal: true
module Grape
module Middleware
# Class to handle the stack of middlewares based on ActionDispatch::MiddlewareStack
# It allows to insert and insert after
class Stack
extend Forwardable
class Middleware
attr_reader :args, :block, :klass
def initi... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/versioner.rb | Ruby | mit | 9,984 | master | 881 | # frozen_string_literal: true
# Versioners set env['api.version'] when a version is defined on an API and
# on the requests. The current methods for determining version are:
#
# :header - version from HTTP Accept header.
# :accept_version_header - version from HTTP Accept-Version header
# :path - version from ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/precomputed_content_types.rb | Ruby | mit | 9,984 | master | 700 | # frozen_string_literal: true
module Grape
module Middleware
# Include in a middleware subclass to warm the content-type caches on the
# parent instance at initialization. Per-request dups inherit the cached
# values via +dup+'s ivar copy, avoiding ~1 µs per request of
# +with_indifferent_access+ rec... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/formatter.rb | Ruby | mit | 9,984 | master | 5,282 | # frozen_string_literal: true
module Grape
module Middleware
class Formatter < Base
include PrecomputedContentTypes
DEFAULT_OPTIONS = {
default_format: :txt
}.freeze
ALL_MEDIA_TYPES = '*/*'
def before
negotiate_content_type
read_body_input
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/filter.rb | Ruby | mit | 9,984 | master | 502 | # frozen_string_literal: true
module Grape
module Middleware
# This is a simple middleware for adding before and after filters
# to Grape APIs. It is used like so:
#
# use Grape::Middleware::Filter, before: -> { do_something }, after: -> { do_something }
class Filter < Base
def before
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/globals.rb | Ruby | mit | 9,984 | master | 432 | # frozen_string_literal: true
module Grape
module Middleware
class Globals < Base
def before
request = Grape::Request.new(@env, build_params_with: @options[:build_params_with])
@env[Grape::Env::GRAPE_REQUEST] = request
@env[Grape::Env::GRAPE_REQUEST_HEADERS] = request.headers
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/base.rb | Ruby | mit | 9,984 | master | 3,056 | # frozen_string_literal: true
module Grape
module Middleware
class Base
include Grape::DSL::Headers
attr_reader :app, :env, :options
# @param [Rack Application] app The standard argument for a Rack middleware.
# @param [Hash] options A hash of options, simply stored for use by subclasse... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/error.rb | Ruby | mit | 9,984 | master | 4,795 | # frozen_string_literal: true
module Grape
module Middleware
class Error < Base
include PrecomputedContentTypes
DEFAULT_OPTIONS = {
default_status: 500,
default_message: '',
format: :txt,
rescue_all: false,
rescue_grape_exceptions: false,
rescue_subcla... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/auth/strategy_info.rb | Ruby | mit | 9,984 | master | 340 | # frozen_string_literal: true
module Grape
module Middleware
module Auth
StrategyInfo = Struct.new(:auth_class, :settings_fetcher) do
def create(app, options, &block)
strategy_args = settings_fetcher.call(options)
auth_class.new(app, *strategy_args, &block)
end
en... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/auth/strategies.rb | Ruby | mit | 9,984 | master | 562 | # frozen_string_literal: true
module Grape
module Middleware
module Auth
module Strategies
module_function
def add(label, strategy, option_fetcher = ->(_) { [] })
auth_strategies[label] = StrategyInfo.new(strategy, option_fetcher)
end
def auth_strategies
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/auth/dsl.rb | Ruby | mit | 9,984 | master | 1,152 | # frozen_string_literal: true
module Grape
module Middleware
module Auth
module DSL
def auth(type = nil, options = {}, &block)
namespace_inheritable = inheritable_setting.namespace_inheritable
return namespace_inheritable[:auth] unless type
namespace_inheritable[:auth... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/auth/base.rb | Ruby | mit | 9,984 | master | 683 | # frozen_string_literal: true
module Grape
module Middleware
module Auth
class Base < Grape::Middleware::Base
def initialize(app, **options)
super
return unless options.key?(:type)
@auth_strategy = Grape::Middleware::Auth::Strategies[options[:type]].tap do |auth_strat... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/versioner/header.rb | Ruby | mit | 9,984 | master | 3,551 | # frozen_string_literal: true
module Grape
module Middleware
module Versioner
# This middleware sets various version related rack environment variables
# based on the HTTP Accept header with the pattern:
# application/vnd.:vendor-:version+:format
#
# Example: For request header
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/versioner/param.rb | Ruby | mit | 9,984 | master | 1,101 | # frozen_string_literal: true
module Grape
module Middleware
module Versioner
# This middleware sets various version related rack environment variables
# based on the request parameters and removes that parameter from the
# request parameters for subsequent middleware and API.
# If the ve... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/versioner/accept_version_header.rb | Ruby | mit | 9,984 | master | 1,194 | # frozen_string_literal: true
module Grape
module Middleware
module Versioner
# This middleware sets various version related rack environment variables
# based on the HTTP Accept-Version header
#
# Example: For request header
# Accept-Version: v1
#
# The following rac... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/versioner/path.rb | Ruby | mit | 9,984 | master | 1,479 | # frozen_string_literal: true
module Grape
module Middleware
module Versioner
# This middleware sets various version related rack environment variables
# based on the uri path and removes the version substring from the uri
# path. If the version substring does not match any potential initialize... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/middleware/versioner/base.rb | Ruby | mit | 9,984 | master | 2,203 | # frozen_string_literal: true
module Grape
module Middleware
module Versioner
class Base < Grape::Middleware::Base
include Grape::Middleware::PrecomputedContentTypes
DEFAULT_OPTIONS = {
pattern: /.*/i,
prefix: nil,
mount_path: nil,
version_options: {... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/serve_stream/stream_response.rb | Ruby | mit | 9,984 | master | 521 | # frozen_string_literal: true
module Grape
module ServeStream
# A simple class used to identify responses which represent streams (or files) and do not
# need to be formatted or pre-read by Rack::Response
class StreamResponse
attr_reader :stream
# @param stream [Object]
def initialize(... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/serve_stream/file_body.rb | Ruby | mit | 9,984 | master | 619 | # frozen_string_literal: true
module Grape
module ServeStream
CHUNK_SIZE = 16_384
# Class helps send file through API
class FileBody
attr_reader :path
# @param path [String]
def initialize(path)
@path = path
end
# Need for Rack::Sendfile middleware
#
#... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/serve_stream/sendfile_response.rb | Ruby | mit | 9,984 | master | 461 | # frozen_string_literal: true
module Grape
module ServeStream
# Response should respond to to_path method
# for using Rack::SendFile middleware
class SendfileResponse < Rack::Response
def respond_to?(method_name, include_all = false)
if method_name == :to_path
@body.respond_to?(:t... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/error_formatter/base.rb | Ruby | mit | 9,984 | master | 2,567 | # frozen_string_literal: true
module Grape
module ErrorFormatter
class Base
class << self
def call(message, backtrace, options = {}, env = nil, original_exception = nil)
merge_backtrace = backtrace.present? && options.dig(:rescue_options, :backtrace)
merge_original_exception = o... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/error_formatter/xml.rb | Ruby | mit | 9,984 | master | 294 | # frozen_string_literal: true
module Grape
module ErrorFormatter
class Xml < Base
def self.format_structured_message(structured_message)
structured_message.respond_to?(:to_xml) ? structured_message.to_xml(root: :error) : structured_message.to_s
end
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/error_formatter/txt.rb | Ruby | mit | 9,984 | master | 704 | # frozen_string_literal: true
module Grape
module ErrorFormatter
class Txt < Base
def self.format_structured_message(structured_message)
message = structured_message[:message] || Grape::Json.dump(structured_message)
Array.wrap(message).tap do |final_message|
if structured_message.... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/error_formatter/json.rb | Ruby | mit | 9,984 | master | 706 | # frozen_string_literal: true
module Grape
module ErrorFormatter
class Json < Base
class << self
def format_structured_message(structured_message)
::Grape::Json.dump(structured_message)
end
private
def wrap_message(message)
case message
when H... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/params_builder/base.rb | Ruby | mit | 9,984 | master | 319 | # frozen_string_literal: true
module Grape
module ParamsBuilder
class Base
class << self
def call(_params)
raise NotImplementedError
end
private
def inherited(klass)
super
ParamsBuilder.register(klass)
end
end
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/params_builder/hash_with_indifferent_access.rb | Ruby | mit | 9,984 | master | 205 | # frozen_string_literal: true
module Grape
module ParamsBuilder
class HashWithIndifferentAccess < Base
def self.call(params)
params.with_indifferent_access
end
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | lib/grape/api/instance.rb | Ruby | mit | 9,984 | master | 6,850 | # frozen_string_literal: true
module Grape
class API
# The API Instance class, is the engine behind Grape::API. Each class that inherits
# from this will represent a different API instance
class Instance
extend Grape::DSL::Settings
extend Grape::DSL::Desc
extend Grape::DSL::Validations
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/spec_helper.rb | Ruby | mit | 9,984 | master | 991 | # frozen_string_literal: true
require 'simplecov'
require 'rubygems'
require 'bundler'
Bundler.require :default, :test
Grape.deprecator.behavior = :raise
%w[support].each do |dir|
Dir["#{File.dirname(__FILE__)}/#{dir}/**/*.rb"].each do |file|
require file
end
end
Grape.config.lint = true # lint all apis by ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/content_type_helpers.rb | Ruby | mit | 9,984 | master | 393 | # frozen_string_literal: true
module Spec
module Support
module Helpers
%w[put patch post delete].each do |method|
define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block|
params = params.to_json
env['CONTENT_TYPE'] ||= 'application/json'
__send__(m... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/versioned_helpers.rb | Ruby | mit | 9,984 | master | 1,592 | # frozen_string_literal: true
# Versioning
module Spec
module Support
module Helpers
# Returns the path with options[:version] prefixed if options[:using] is :path.
# Returns normal path otherwise.
def versioned_path(options)
case options[:using]
when :path
File.join('... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/cookie_jar.rb | Ruby | mit | 9,984 | master | 1,362 | # frozen_string_literal: true
require 'uri'
module Spec
module Support
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
class CookieJar
attr_reader :attributes
def initialize(raw)
@attributes = raw.split(/;\s*/).flat_map.with_index do |attribute, i|
attrib... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/deprecated_warning_handlers.rb | Ruby | mit | 9,984 | master | 432 | # frozen_string_literal: true
Warning[:deprecated] = true
module DeprecatedWarningHandler
class DeprecationWarning < StandardError; end
DEPRECATION_REGEX = /is deprecated/
def warn(message)
return super unless message.match?(DEPRECATION_REGEX)
exception = DeprecationWarning.new(message)
exception... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/chunked_response.rb | Ruby | mit | 9,984 | master | 1,600 | # frozen_string_literal: true
# this is a copy of Rack::Chunked which has been removed in rack > 3.0
class ChunkedResponse
class Body
TERM = "\r\n"
TAIL = "0#{TERM}".freeze
# Store the response body to be chunked.
def initialize(body)
@body = body
end
# For each element yielded by th... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/integer_helpers.rb | Ruby | mit | 9,984 | master | 211 | # frozen_string_literal: true
module Spec
module Support
module Helpers
INTEGER_CLASS_NAME = 0.class.to_s.freeze
def integer_class_name
INTEGER_CLASS_NAME
end
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/endpoint_faker.rb | Ruby | mit | 9,984 | master | 481 | # frozen_string_literal: true
module Spec
module Support
class EndpointFaker
class FakerAPI < Grape::API
get('/')
end
def initialize(app, endpoint = FakerAPI.endpoints.first)
@app = app
@endpoint = endpoint
end
def call(env)
@endpoint.instance_exec ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/file_streamer.rb | Ruby | mit | 9,984 | master | 215 | # frozen_string_literal: true
class FileStreamer
def initialize(file_path)
@file_path = file_path
end
def each(&blk)
File.open(@file_path, 'rb') do |file|
file.each(10, &blk)
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/support/basic_auth_encode_helpers.rb | Ruby | mit | 9,984 | master | 217 | # frozen_string_literal: true
module Spec
module Support
module Helpers
def encode_basic_auth(username, password)
"Basic #{Base64.encode64("#{username}:#{password}")}"
end
end
end
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/shared/versioning_examples.rb | Ruby | mit | 9,984 | master | 6,158 | # frozen_string_literal: true
shared_examples_for 'versioning' do
it 'sets the API version' do
subject.format :txt
subject.version 'v1', **macro_options
subject.get :hello do
"Version: #{request.env[Grape::Env::API_VERSION]}"
end
versioned_get '/hello', 'v1', macro_options
expect(last_r... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/integration/dry_validation/dry_validation_spec.rb | Ruby | mit | 9,984 | master | 5,668 | # frozen_string_literal: true
describe 'Dry::Schema', if: defined?(Dry::Schema) do
describe 'Grape::DSL::Validations' do
subject { app }
let(:app) do
Class.new do
extend Grape::DSL::Validations
extend Grape::DSL::Settings
end
end
describe '.contract' do
it 'saves t... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/integration/grape_entity/entity_spec.rb | Ruby | mit | 9,984 | master | 11,087 | # frozen_string_literal: true
require 'rack/contrib/jsonp'
describe 'Grape::Entity', if: defined?(Grape::Entity) do
describe '#present' do
subject { Class.new(Grape::API) }
let(:app) { subject }
before do
stub_const('TestObject', Class.new)
stub_const('FakeCollection', Class.new do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/integration/hashie/hashie_spec.rb | Ruby | mit | 9,984 | master | 8,950 | # frozen_string_literal: true
describe 'Hashie', if: defined?(Hashie) do
subject { app }
let(:app) { Class.new(Grape::API) }
describe 'Grape::ParamsBuilder::HashieMash' do
describe 'in an endpoint' do
describe '#params' do
before do
subject.params do
build_with :hashie_m... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/integration/multi_json/json_spec.rb | Ruby | mit | 9,984 | master | 242 | # frozen_string_literal: true
# grape_entity depends on multi-json and it breaks the test.
describe Grape::Json, if: defined?(MultiJson) && !defined?(Grape::Entity) do
subject { described_class }
it { is_expected.to eq(MultiJson) }
end |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/integration/rails/mounting_spec.rb | Ruby | mit | 9,984 | master | 1,353 | # frozen_string_literal: true
describe 'Rails', if: defined?(Rails) do
context 'rails mounted' do
let(:api) do
Class.new(Grape::API) do
lint!
get('/test_grape') { 'rails mounted' }
end
end
let(:app) do
require 'rails'
require 'action_controller/railtie'
# h... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/integration/rails/railtie_spec.rb | Ruby | mit | 9,984 | master | 705 | # frozen_string_literal: true
if defined?(Rails)
describe Grape::Railtie do
describe '.railtie' do
subject { test_app.deprecators[:grape] }
let(:test_app) do
# https://github.com/rails/rails/issues/51784
# same error as described if not redefining the following
ActiveSupport:... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api_remount_spec.rb | Ruby | mit | 9,984 | master | 18,081 | # frozen_string_literal: true
require 'shared/versioning_examples'
describe Grape::API do
subject(:a_remounted_api) { Class.new(described_class) }
let(:root_api) { Class.new(described_class) }
let(:app) { root_api }
describe 'remounting an API' do
context 'with a defined route' do
before do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/request_spec.rb | Ruby | mit | 9,984 | master | 5,551 | # frozen_string_literal: true
describe Grape::Request do
let(:default_method) { Rack::GET }
let(:default_params) { {} }
let(:default_options) do
{
method:,
params:
}
end
let(:default_env) do
Rack::MockRequest.env_for('/', options)
end
let(:method) { default_method }
let(:params)... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/router_spec.rb | Ruby | mit | 9,984 | master | 1,279 | # frozen_string_literal: true
describe Grape::Router do
describe '.normalize_path' do
subject { described_class.normalize_path(path) }
context 'when no leading slash' do
let(:path) { 'foo%20bar%20baz' }
it { is_expected.to eq '/foo%20bar%20baz' }
end
context 'when path ends with slash'... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/named_api_spec.rb | Ruby | mit | 9,984 | master | 379 | # frozen_string_literal: true
describe Grape::API do
subject(:api_name) { NamedAPI.endpoints.last.options[:for].to_s }
let(:api) do
Class.new(Grape::API) do
get 'test' do
'response'
end
end
end
let(:name) { 'NamedAPI' }
before { stub_const(name, api) }
it 'can access the nam... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/endpoint_spec.rb | Ruby | mit | 9,984 | master | 31,908 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
it 'sets itself in the env upon call' do
subject.get('/') { 'Hello world.' }
get '/'
expect(last_request.env[Grape::Env::API_ENDPOINT]).to be_a(described_class)
end
describe '#... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/testing_spec.rb | Ruby | mit | 9,984 | master | 1,368 | # frozen_string_literal: true
require 'grape/testing'
describe Grape::Testing do
subject { Class.new(Grape::API) }
let(:app) { subject }
describe 'Grape::Endpoint.before_each' do
after { Grape::Endpoint.reset_before_each }
it 'is able to override a helper' do
subject.get('/') { current_user }
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api_spec.rb | Ruby | mit | 9,984 | master | 131,079 | # frozen_string_literal: true
require 'shared/versioning_examples'
describe Grape::API do
subject { Class.new(described_class) }
let(:app) { subject }
describe '.prefix' do
it 'routes root through with the prefix' do
subject.prefix 'awesome/sauce'
subject.get do
'Hello there.'
en... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/validations_spec.rb | Ruby | mit | 9,984 | master | 72,941 | # frozen_string_literal: true
describe Grape::Validations do
subject { Class.new(Grape::API) }
let(:app) { subject }
describe 'params' do
context 'optional' do
before do
subject.params do
optional :a_number, regexp: /^[0-9]+$/
optional :attachment, type: File
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/content_types_spec.rb | Ruby | mit | 9,984 | master | 1,928 | # frozen_string_literal: true
describe Grape::ContentTypes do
describe 'DEFAULTS' do
subject { described_class::DEFAULTS }
let(:expected_value) do
{
xml: 'application/xml',
serializable_hash: 'application/json',
json: 'application/json',
binary: 'application/octet-strea... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/path_spec.rb | Ruby | mit | 9,984 | master | 2,574 | # frozen_string_literal: true
describe Grape::Path do
describe '#origin' do
context 'mount_path' do
it 'is not included when it is nil' do
path = described_class.new(nil, nil, mount_path: '/foo/bar')
expect(path.origin).to eql '/foo/bar'
end
it 'is included when it is not nil' ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/loading_spec.rb | Ruby | mit | 9,984 | master | 823 | # frozen_string_literal: true
describe Grape::API do
subject do
context = self
Class.new(Grape::API) do
format :json
mount context.combined_api => '/'
end
end
let(:jobs_api) do
Class.new(Grape::API) do
namespace :one do
namespace :two do
namespace :three do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/parser_spec.rb | Ruby | mit | 9,984 | master | 696 | # frozen_string_literal: true
describe Grape::Parser do
subject { described_class }
describe '.parser_for' do
let(:options) { {} }
it 'returns parser correctly' do
expect(subject.parser_for(:json)).to eq(Grape::Parser::Json)
end
context 'when parser is available' do
let(:parsers) do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/instance_spec.rb | Ruby | mit | 9,984 | master | 2,288 | # frozen_string_literal: true
require 'shared/versioning_examples'
describe Grape::API::Instance do
subject(:an_instance) do
Class.new(Grape::API::Instance) do
namespace :some_namespace do
get 'some_endpoint' do
'success'
end
end
end
end
let(:root_api) do
to_mo... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/parameters_modification_spec.rb | Ruby | mit | 9,984 | master | 895 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :test do
params do
optional :foo, default: +'-abcdef'
end
get do
params[:foo].slice!(0)
params[:foo]
end
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/mount_and_helpers_order_spec.rb | Ruby | mit | 9,984 | master | 4,863 | # frozen_string_literal: true
describe Grape::API do
describe 'rescue_from' do
context 'when the API is mounted AFTER defining the class rescue_from handler' do
let(:api_rescue_from) do
Class.new(Grape::API) do
rescue_from :all do
error!({ type: 'all' }, 404)
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/mounted_helpers_inheritance_spec.rb | Ruby | mit | 9,984 | master | 748 | # frozen_string_literal: true
describe Grape::API do
context 'when mounting a child API that inherits helpers from parent API' do
let(:child_api) do
Class.new(Grape::API) do
get '/test' do
parent_helper
end
end
end
let(:parent_api) do
context = self
Clas... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/namespace_parameters_in_route_spec.rb | Ruby | mit | 9,984 | master | 670 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :me do
namespace :pending do
get '/' do
'banana'
end
end
put ':id' do
params[:id]
end
end
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/deeply_included_options_spec.rb | Ruby | mit | 9,984 | master | 1,164 | # frozen_string_literal: true
describe Grape::API do
let(:app) do
main_api = api
Class.new(Grape::API) do
mount main_api
end
end
let(:api) do
deeply_included_options = options
Class.new(Grape::API) do
include deeply_included_options
resource :users do
get do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/invalid_format_spec.rb | Ruby | mit | 9,984 | master | 998 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace do
format :json
content_type :json, 'application/json'
params do
requires :id, desc: 'Identifier.'
end
get ':id' do
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/required_parameters_in_route_spec.rb | Ruby | mit | 9,984 | master | 670 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :api do
get ':id' do
[params[:id], params[:ext]].compact.join('/')
end
put ':something_id' do
params[:something_id]
end
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/patch_method_helpers_spec.rb | Ruby | mit | 9,984 | master | 1,850 | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:patch_public) do
Class.new(Grape::API) do
format :json
version 'public-v1', using: :header, vendor: 'grape'
get do
{ ok: 'public' }
end
end
end
let(:auth_methods) do
Module.new do
def authenticat... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/shared_helpers_exactly_one_of_spec.rb | Ruby | mit | 9,984 | master | 1,075 | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:app) do
Class.new(Grape::API) do
helpers Module.new do
extend Grape::API::Helpers
params :drink do
optional :beer
optional :wine
exactly_one_of :beer, :wine
end
end
format :... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/nested_helpers_spec.rb | Ruby | mit | 9,984 | master | 998 | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:helper_methods) do
Module.new do
extend Grape::API::Helpers
def current_user
@current_user ||= params[:current_user]
end
end
end
let(:nested) do
context = self
Class.new(Grape::API) do
resource :l... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/routes_with_requirements_spec.rb | Ruby | mit | 9,984 | master | 2,080 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
context 'get' do
it 'routes to a namespace param with dots' do
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
get '/' do
params[:ns_... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/optional_parameters_in_route_spec.rb | Ruby | mit | 9,984 | master | 827 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :api do
get ':id(/:ext)' do
[params[:id], params[:ext]].compact.join('/')
end
put ':id' do
params[:id]
end
end
end... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/mount_and_rescue_from_spec.rb | Ruby | mit | 9,984 | master | 2,406 | # frozen_string_literal: true
describe Grape::API do
context 'when multiple classes defines the same rescue_from' do
let(:an_api) do
Class.new(Grape::API) do
rescue_from ZeroDivisionError do
error!({ type: 'an-api-zero' }, 404)
end
get '/an-api' do
{ count: 1 / ... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/recognize_path_spec.rb | Ruby | mit | 9,984 | master | 2,424 | # frozen_string_literal: true
describe Grape::API do
describe '.recognize_path' do
subject { Class.new(described_class) }
it 'fetches endpoint by given path' do
subject.get('/foo/:id') {}
subject.get('/bar/:id') {}
subject.get('/baz/:id') {}
actual = subject.recognize_path('/bar/123... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/documentation_spec.rb | Ruby | mit | 9,984 | master | 1,473 | # frozen_string_literal: true
describe Grape::API do
subject { Class.new(described_class) }
let(:app) { subject }
context 'an endpoint with documentation' do
it 'documents parameters' do
subject.params do
requires 'price', type: Float, desc: 'Sales price'
end
subject.get '/'
... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/required_parameters_with_invalid_method_spec.rb | Ruby | mit | 9,984 | master | 397 | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace do
params do
requires :id, desc: 'Identifier.'
end
get ':id' do
end
end
end
context 'post' do
it '405' do
post... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/defines_boolean_in_params_spec.rb | Ruby | mit | 9,984 | master | 624 | # frozen_string_literal: true
describe Grape::API::Instance do
describe 'boolean constant' do
let(:app) do
Class.new(Grape::API) do
params do
requires :message, type: Grape::API::Boolean
end
post :echo do
{ class: params[:message].class.name, value: params[:messa... |
github | ruby-grape/grape | https://github.com/ruby-grape/grape | spec/grape/api/shared_helpers_spec.rb | Ruby | mit | 9,984 | master | 674 | # frozen_string_literal: true
describe Grape::API::Helpers do
subject do
shared_params = Module.new do
extend Grape::API::Helpers
params :pagination do
optional :page, type: Integer
optional :size, type: Integer
end
end
Class.new(Grape::API) do
helpers shared_par... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.