repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/types/primitive_coercer_spec.rb | spec/grape/validations/types/primitive_coercer_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Types::PrimitiveCoercer do
subject { described_class.new(type, strict) }
let(:strict) { false }
describe '#call' do
context 'BigDecimal' do
let(:type) { BigDecimal }
it 'coerces to BigDecimal' do
expect(subject.call(5)).to eq(B... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/types/set_coercer_spec.rb | spec/grape/validations/types/set_coercer_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Types::SetCoercer do
subject { described_class.new(type) }
describe '#call' do
context 'a set of primitives' do
let(:type) { Set[String] }
it 'coerces elements to the set' do
expect(subject.call([10, 20])).to eq(Set['10', '20'])
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/types/array_coercer_spec.rb | spec/grape/validations/types/array_coercer_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Types::ArrayCoercer do
subject { described_class.new(type) }
describe '#call' do
context 'an array of primitives' do
let(:type) { Array[String] }
it 'coerces elements in the array' do
expect(subject.call([10, 20])).to eq(%w[10 20]... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/router/greedy_route_spec.rb | spec/grape/router/greedy_route_spec.rb | # frozen_string_literal: true
RSpec.describe Grape::Router::GreedyRoute do
let(:instance) { described_class.new(pattern, endpoint: endpoint, allow_header: allow_header) }
let(:pattern) { :pattern }
let(:endpoint) { instance_double(Grape::Endpoint) }
let(:allow_header) { false }
describe 'inheritance' do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/endpoint/declared_spec.rb | spec/grape/endpoint/declared_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
let(:app) { subject }
describe '#declared' do
before do
subject.format :json
subject.params do
requires :first
optional :second
optional :third, default: 'third-default'
o... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/config/spec_test_prof.rb | spec/config/spec_test_prof.rb | # frozen_string_literal: true
require 'test_prof/recipes/rspec/let_it_be'
TestProf::BeforeAll.adapter = Class.new do
def begin_transaction; end
def rollback_transaction; end
end.new
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/shared/versioning_examples.rb | spec/shared/versioning_examples.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape.rb | lib/grape.rb | # frozen_string_literal: true
require 'logger'
require 'active_support'
require 'active_support/version'
require 'active_support/isolated_execution_state'
require 'active_support/core_ext/array/conversions' # to_xml
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/conversions' # to_xm... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/dry_types.rb | lib/grape/dry_types.rb | # frozen_string_literal: true
module Grape
module DryTypes
# https://dry-rb.org/gems/dry-types/main/getting-started/
# limit to what Grape is using
include Dry.Types(:params, :coercible, :strict)
class StrictCache < Grape::Util::Cache
MAPPING = {
Grape::API::Boolean => DryTypes::Strict... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/path.rb | lib/grape/path.rb | # frozen_string_literal: true
module Grape
# Represents a path to an endpoint.
class Path
DEFAULT_FORMAT_SEGMENT = '(/.:format)'
NO_VERSIONING_WITH_VALID_PATH_FORMAT_SEGMENT = '(.:format)'
VERSION_SEGMENT = ':version'
attr_reader :origin, :suffix
def initialize(raw_path, raw_namespace, settin... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/cookies.rb | lib/grape/cookies.rb | # frozen_string_literal: true
module Grape
class Cookies
extend Forwardable
DELETED_COOKIES_ATTRS = {
max_age: '0',
value: '',
expires: Time.at(0)
}.freeze
def_delegators :cookies, :[], :each
def initialize(rack_cookies)
@cookies = rack_cookies
@send_cookies = nil... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/content_types.rb | lib/grape/content_types.rb | # frozen_string_literal: true
module Grape
module ContentTypes
module_function
# Content types are listed in order of preference.
DEFAULTS = {
xml: 'application/xml',
serializable_hash: 'application/json',
json: 'application/json',
binary: 'application/octet-stream',
txt: '... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/version.rb | lib/grape/version.rb | # frozen_string_literal: true
module Grape
# The current version of Grape.
VERSION = '3.1.0'
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/declared_params_handler.rb | lib/grape/declared_params_handler.rb | # frozen_string_literal: true
module Grape
class DeclaredParamsHandler
def initialize(include_missing: true, evaluate_given: false, stringify: false, contract_key_map: nil)
@include_missing = include_missing
@evaluate_given = evaluate_given
@stringify = stringify
@contract_key_map = contr... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/namespace.rb | lib/grape/namespace.rb | # frozen_string_literal: true
module Grape
# A container for endpoints or other namespaces, which allows for both
# logical grouping of endpoints as well as sharing common configuration.
# May also be referred to as group, segment, or resource.
class Namespace
attr_reader :space, :requirements, :options
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/xml.rb | lib/grape/xml.rb | # frozen_string_literal: true
module Grape
if defined?(::MultiXml)
Xml = ::MultiXml
else
Xml = ::ActiveSupport::XmlMini
Xml::ParseError = StandardError
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/error_formatter.rb | lib/grape/error_formatter.rb | # frozen_string_literal: true
module Grape
module ErrorFormatter
extend Grape::Util::Registry
module_function
def formatter_for(format, error_formatters = nil, default_error_formatter = nil)
return error_formatters[format] if error_formatters&.key?(format)
registry[format] || default_error... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/router.rb | lib/grape/router.rb | # frozen_string_literal: true
module Grape
class Router
# Taken from Rails
# normalize_path("/foo") # => "/foo"
# normalize_path("/foo/") # => "/foo"
# normalize_path("foo") # => "/foo"
# normalize_path("") # => "/"
# normalize_path("/%ab") # => "/%AB"
# https... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/params_builder.rb | lib/grape/params_builder.rb | # frozen_string_literal: true
module Grape
module ParamsBuilder
extend Grape::Util::Registry
module_function
def params_builder_for(short_name)
raise Grape::Exceptions::UnknownParamsBuilder, short_name unless registry.key?(short_name)
registry[short_name]
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/parser.rb | lib/grape/parser.rb | # frozen_string_literal: true
module Grape
module Parser
extend Grape::Util::Registry
module_function
def parser_for(format, parsers = nil)
return parsers[format] if parsers&.key?(format)
registry[format]
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/validations.rb | lib/grape/validations.rb | # frozen_string_literal: true
module Grape
module Validations
extend Grape::Util::Registry
module_function
def require_validator(short_name)
raise Grape::Exceptions::UnknownValidator, short_name unless registry.key?(short_name)
registry[short_name]
end
def build_short_name(klass)
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/json.rb | lib/grape/json.rb | # frozen_string_literal: true
module Grape
if defined?(::MultiJson)
Json = ::MultiJson
else
Json = ::JSON
Json::ParseError = Json::ParserError
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/env.rb | lib/grape/env.rb | # frozen_string_literal: true
module Grape
module Env
API_VERSION = 'api.version'
API_ENDPOINT = 'api.endpoint'
API_REQUEST_INPUT = 'api.request.input'
API_REQUEST_BODY = 'api.request.body'
API_TYPE = 'api.type'
API_SUBTYPE = 'api.subtype'
API_VENDOR = 'api.vendor'
API_FORMAT = 'api.f... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/railtie.rb | lib/grape/railtie.rb | # frozen_string_literal: true
module Grape
class Railtie < ::Rails::Railtie
initializer 'grape.deprecator' do |app|
app.deprecators[:grape] = Grape.deprecator
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/api.rb | lib/grape/api.rb | # frozen_string_literal: true
module Grape
# The API class is the primary entry point for creating Grape APIs. Users
# should subclass this class in order to build an API.
class API
# Class methods that we want to call on the API rather than on the API object
NON_OVERRIDABLE = %i[base= base_instance? cal... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/endpoint.rb | lib/grape/endpoint.rb | # frozen_string_literal: true
module Grape
# An Endpoint is the proxy scope in which all routing
# blocks are executed. In other words, any methods
# on the instance level of this class may be called
# from inside a `get`, `post`, etc.
class Endpoint
extend Forwardable
include Grape::DSL::Settings
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/request.rb | lib/grape/request.rb | # frozen_string_literal: true
module Grape
class Request < Rack::Request
# Based on rack 3 KNOWN_HEADERS
# https://github.com/rack/rack/blob/4f15e7b814922af79605be4b02c5b7c3044ba206/lib/rack/headers.rb#L10
KNOWN_HEADERS = %w[
Accept
Accept-CH
Accept-Encoding
Accept-Language
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/formatter.rb | lib/grape/formatter.rb | # frozen_string_literal: true
module Grape
module Formatter
extend Grape::Util::Registry
module_function
DEFAULT_LAMBDA_FORMATTER = ->(obj, _env) { obj }
def formatter_for(api_format, formatters)
return formatters[api_format] if formatters&.key?(api_format)
registry[api_format] || DEF... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/registry.rb | lib/grape/util/registry.rb | # frozen_string_literal: true
module Grape
module Util
module Registry
def register(klass)
short_name = build_short_name(klass)
return if short_name.nil?
warn "#{short_name} is already registered with class #{registry[short_name]}. It will be overridden globally with the following:... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/base_inheritable.rb | lib/grape/util/base_inheritable.rb | # frozen_string_literal: true
module Grape
module Util
# Base for classes which need to operate with own values kept
# in the hash and inherited values kept in a Hash-like object.
class BaseInheritable
attr_accessor :inherited_values, :new_values
# @param inherited_values [Object] An object ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/api_description.rb | lib/grape/util/api_description.rb | # frozen_string_literal: true
module Grape
module Util
class ApiDescription
DSL_METHODS = %i[
body_name
consumes
default
deprecated
detail
entity
headers
hidden
http_codes
is_array
named
nickname
params
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/endpoint_configuration.rb | lib/grape/util/endpoint_configuration.rb | # frozen_string_literal: true
module Grape
module Util
class EndpointConfiguration < Lazy::ValueHash
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/reverse_stackable_values.rb | lib/grape/util/reverse_stackable_values.rb | # frozen_string_literal: true
module Grape
module Util
class ReverseStackableValues < StackableValues
protected
def concat_values(inherited_value, new_value)
return inherited_value unless new_value
new_value + inherited_value
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/media_type.rb | lib/grape/util/media_type.rb | # frozen_string_literal: true
module Grape
module Util
class MediaType
attr_reader :type, :subtype, :vendor, :version, :format
# based on the HTTP Accept header with the pattern:
# application/vnd.:vendor-:version+:format
VENDOR_VERSION_HEADER_REGEX = /\Avnd\.(?<vendor>[a-z0-9.\-_!^]+?)(... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/inheritable_setting.rb | lib/grape/util/inheritable_setting.rb | # frozen_string_literal: true
module Grape
module Util
# A branchable, inheritable settings object which can store both stackable
# and inheritable values (see InheritableValues and StackableValues).
class InheritableSetting
attr_accessor :route, :api_class, :namespace, :namespace_inheritable, :nam... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/inheritable_values.rb | lib/grape/util/inheritable_values.rb | # frozen_string_literal: true
module Grape
module Util
class InheritableValues < BaseInheritable
def [](name)
values[name]
end
def []=(name, value)
new_values[name] = value
end
def merge(new_hash)
values.merge!(new_hash)
end
def to_hash
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/stackable_values.rb | lib/grape/util/stackable_values.rb | # frozen_string_literal: true
module Grape
module Util
class StackableValues < BaseInheritable
# Even if there is no value, an empty array will be returned.
def [](name)
inherited_value = inherited_values[name]
new_value = new_values[name]
return new_value || [] unless inheri... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/header.rb | lib/grape/util/header.rb | # frozen_string_literal: true
module Grape
module Util
if Gem::Version.new(Rack.release) >= Gem::Version.new('3')
require 'rack/headers'
Header = Rack::Headers
else
require 'rack/utils'
Header = Rack::Utils::HeaderHash
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/cache.rb | lib/grape/util/cache.rb | # frozen_string_literal: true
module Grape
module Util
class Cache
include Singleton
attr_reader :cache
class << self
extend Forwardable
def_delegators :cache, :[]
def_delegators :instance, :cache
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/lazy/value.rb | lib/grape/util/lazy/value.rb | # frozen_string_literal: true
module Grape
module Util
module Lazy
class Value
attr_reader :access_keys
def initialize(value, access_keys = [])
@value = value
@access_keys = access_keys
end
def evaluate_from(configuration)
matching_lazy_value ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/lazy/value_enumerable.rb | lib/grape/util/lazy/value_enumerable.rb | # frozen_string_literal: true
module Grape
module Util
module Lazy
class ValueEnumerable < Value
def [](key)
if @value_hash[key].nil?
Value.new(nil).reached_by(access_keys, key)
else
@value_hash[key].reached_by(access_keys, key)
end
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/lazy/value_array.rb | lib/grape/util/lazy/value_array.rb | # frozen_string_literal: true
module Grape
module Util
module Lazy
class ValueArray < ValueEnumerable
def initialize(array)
super
@value_hash = []
array.each_with_index do |value, index|
self[index] = value
end
end
def evaluate
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/lazy/value_hash.rb | lib/grape/util/lazy/value_hash.rb | # frozen_string_literal: true
module Grape
module Util
module Lazy
class ValueHash < ValueEnumerable
def initialize(hash)
super
@value_hash = ActiveSupport::HashWithIndifferentAccess.new
hash.each do |key, value|
self[key] = value
end
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/util/lazy/block.rb | lib/grape/util/lazy/block.rb | # frozen_string_literal: true
module Grape
module Util
module Lazy
class Block
def initialize(&new_block)
@block = new_block
end
def evaluate_from(configuration)
@block.call(configuration)
end
def evaluate
@block.call({})
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/params_builder/hash_with_indifferent_access.rb | lib/grape/params_builder/hash_with_indifferent_access.rb | # frozen_string_literal: true
module Grape
module ParamsBuilder
class HashWithIndifferentAccess < Base
def self.call(params)
params.with_indifferent_access
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/params_builder/base.rb | lib/grape/params_builder/base.rb | # 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
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/params_builder/hashie_mash.rb | lib/grape/params_builder/hashie_mash.rb | # frozen_string_literal: true
module Grape
module ParamsBuilder
class HashieMash < Base
def self.call(params)
::Hashie::Mash.new(params)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/params_builder/hash.rb | lib/grape/params_builder/hash.rb | # frozen_string_literal: true
module Grape
module ParamsBuilder
class Hash < Base
def self.call(params)
params.deep_symbolize_keys
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/serve_stream/file_body.rb | lib/grape/serve_stream/file_body.rb | # 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
#
#... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/serve_stream/sendfile_response.rb | lib/grape/serve_stream/sendfile_response.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/serve_stream/stream_response.rb | lib/grape/serve_stream/stream_response.rb | # 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(... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/presenters/presenter.rb | lib/grape/presenters/presenter.rb | # frozen_string_literal: true
module Grape
module Presenters
class Presenter
def self.represent(object, **_options)
object
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/unknown_parameter.rb | lib/grape/exceptions/unknown_parameter.rb | # frozen_string_literal: true
module Grape
module Exceptions
class UnknownParameter < Base
def initialize(param)
super(message: compose_message(:unknown_parameter, param: param))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/empty_message_body.rb | lib/grape/exceptions/empty_message_body.rb | # frozen_string_literal: true
module Grape
module Exceptions
class EmptyMessageBody < Base
def initialize(body_format)
super(message: compose_message(:empty_message_body, body_format: body_format), status: 400)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_formatter.rb | lib/grape/exceptions/invalid_formatter.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidFormatter < Base
def initialize(klass, to_format)
super(message: compose_message(:invalid_formatter, klass: klass, to_format: to_format))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/validation_errors.rb | lib/grape/exceptions/validation_errors.rb | # frozen_string_literal: true
module Grape
module Exceptions
class ValidationErrors < Base
ERRORS_FORMAT_KEY = 'grape.errors.format'
DEFAULT_ERRORS_FORMAT = '%<attributes>s %<message>s'
include Enumerable
attr_reader :errors
def initialize(errors: [], headers: {})
@errors... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/unknown_params_builder.rb | lib/grape/exceptions/unknown_params_builder.rb | # frozen_string_literal: true
module Grape
module Exceptions
class UnknownParamsBuilder < Base
def initialize(params_builder_type)
super(message: compose_message(:unknown_params_builder, params_builder_type: params_builder_type))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/missing_vendor_option.rb | lib/grape/exceptions/missing_vendor_option.rb | # frozen_string_literal: true
module Grape
module Exceptions
class MissingVendorOption < Base
def initialize
super(message: compose_message(:missing_vendor_option))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_message_body.rb | lib/grape/exceptions/invalid_message_body.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidMessageBody < Base
def initialize(body_format)
super(message: compose_message(:invalid_message_body, body_format: body_format), status: 400)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/conflicting_types.rb | lib/grape/exceptions/conflicting_types.rb | # frozen_string_literal: true
module Grape
module Exceptions
class ConflictingTypes < Base
def initialize
super(message: compose_message(:conflicting_types), status: 400)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/missing_group_type.rb | lib/grape/exceptions/missing_group_type.rb | # frozen_string_literal: true
module Grape
module Exceptions
class MissingGroupType < Base
def initialize
super(message: compose_message(:missing_group_type))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_with_option_for_represent.rb | lib/grape/exceptions/invalid_with_option_for_represent.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidWithOptionForRepresent < Base
def initialize
super(message: compose_message(:invalid_with_option_for_represent))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/unknown_validator.rb | lib/grape/exceptions/unknown_validator.rb | # frozen_string_literal: true
module Grape
module Exceptions
class UnknownValidator < Base
def initialize(validator_type)
super(message: compose_message(:unknown_validator, validator_type: validator_type))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_response.rb | lib/grape/exceptions/invalid_response.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidResponse < Base
def initialize
super(message: compose_message(:invalid_response))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/too_deep_parameters.rb | lib/grape/exceptions/too_deep_parameters.rb | # frozen_string_literal: true
module Grape
module Exceptions
class TooDeepParameters < Base
def initialize(limit)
super(message: compose_message(:too_deep_parameters, limit: limit), status: 400)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_versioner_option.rb | lib/grape/exceptions/invalid_versioner_option.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidVersionerOption < Base
def initialize(strategy)
super(message: compose_message(:invalid_versioner_option, strategy: strategy))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/unknown_auth_strategy.rb | lib/grape/exceptions/unknown_auth_strategy.rb | # frozen_string_literal: true
module Grape
module Exceptions
class UnknownAuthStrategy < Base
def initialize(strategy:)
super(message: compose_message(:unknown_auth_strategy, strategy: strategy))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_version_header.rb | lib/grape/exceptions/invalid_version_header.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidVersionHeader < Base
def initialize(message, headers)
super(message: compose_message(:invalid_version_header, message: message), status: 406, headers: headers)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/too_many_multipart_files.rb | lib/grape/exceptions/too_many_multipart_files.rb | # frozen_string_literal: true
module Grape
module Exceptions
class TooManyMultipartFiles < Base
def initialize(limit)
super(message: compose_message(:too_many_multipart_files, limit: limit), status: 413)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/unsupported_group_type.rb | lib/grape/exceptions/unsupported_group_type.rb | # frozen_string_literal: true
module Grape
module Exceptions
class UnsupportedGroupType < Base
def initialize
super(message: compose_message(:unsupported_group_type))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_parameters.rb | lib/grape/exceptions/invalid_parameters.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidParameters < Base
def initialize
super(message: compose_message(:invalid_parameters), status: 400)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/invalid_accept_header.rb | lib/grape/exceptions/invalid_accept_header.rb | # frozen_string_literal: true
module Grape
module Exceptions
class InvalidAcceptHeader < Base
def initialize(message, headers)
super(message: compose_message(:invalid_accept_header, message: message), status: 406, headers: headers)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/base.rb | lib/grape/exceptions/base.rb | # frozen_string_literal: true
module Grape
module Exceptions
class Base < StandardError
BASE_MESSAGES_KEY = 'grape.errors.messages'
BASE_ATTRIBUTES_KEY = 'grape.errors.attributes'
FALLBACK_LOCALE = :en
attr_reader :status, :headers
def initialize(status: nil, message: nil, headers... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/method_not_allowed.rb | lib/grape/exceptions/method_not_allowed.rb | # frozen_string_literal: true
module Grape
module Exceptions
class MethodNotAllowed < Base
def initialize(headers)
super(message: '405 Not Allowed', status: 405, headers: headers)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/incompatible_option_values.rb | lib/grape/exceptions/incompatible_option_values.rb | # frozen_string_literal: true
module Grape
module Exceptions
class IncompatibleOptionValues < Base
def initialize(option1, value1, option2, value2)
super(message: compose_message(:incompatible_option_values, option1: option1, value1: value1, option2: option2, value2: value2))
end
end
en... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/missing_mime_type.rb | lib/grape/exceptions/missing_mime_type.rb | # frozen_string_literal: true
module Grape
module Exceptions
class MissingMimeType < Base
def initialize(new_format)
super(message: compose_message(:missing_mime_type, new_format: new_format))
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/validation.rb | lib/grape/exceptions/validation.rb | # frozen_string_literal: true
module Grape
module Exceptions
class Validation < Base
attr_accessor :params, :message_key
def initialize(params:, message: nil, status: nil, headers: nil)
@params = params
if message
@message_key = message if message.is_a?(Symbol)
me... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/exceptions/validation_array_errors.rb | lib/grape/exceptions/validation_array_errors.rb | # frozen_string_literal: true
module Grape
module Exceptions
class ValidationArrayErrors < Base
attr_reader :errors
def initialize(errors)
super()
@errors = errors
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/globals.rb | lib/grape/middleware/globals.rb | # 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
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/filter.rb | lib/grape/middleware/filter.rb | # 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
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/stack.rb | lib/grape/middleware/stack.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/base.rb | lib/grape/middleware/base.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/versioner.rb | lib/grape/middleware/versioner.rb | # 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 ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/formatter.rb | lib/grape/middleware/formatter.rb | # frozen_string_literal: true
module Grape
module Middleware
class Formatter < Base
DEFAULT_OPTIONS = {
default_format: :txt
}.freeze
ALL_MEDIA_TYPES = '*/*'
def before
negotiate_content_type
read_body_input
end
def after
return unless @app_r... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/error.rb | lib/grape/middleware/error.rb | # frozen_string_literal: true
module Grape
module Middleware
class Error < Base
DEFAULT_OPTIONS = {
default_status: 500,
default_message: '',
format: :txt,
rescue_all: false,
rescue_grape_exceptions: false,
rescue_subclasses: true,
rescue_options: {
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/auth/strategies.rb | lib/grape/middleware/auth/strategies.rb | # 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
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/auth/strategy_info.rb | lib/grape/middleware/auth/strategy_info.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/auth/dsl.rb | lib/grape/middleware/auth/dsl.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/auth/base.rb | lib/grape/middleware/auth/base.rb | # frozen_string_literal: true
module Grape
module Middleware
module Auth
class Base < Grape::Middleware::Base
def initialize(app, **options)
super
@auth_strategy = Grape::Middleware::Auth::Strategies[options[:type]].tap do |auth_strategy|
raise Grape::Exceptions::Unk... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/versioner/path.rb | lib/grape/middleware/versioner/path.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/versioner/param.rb | lib/grape/middleware/versioner/param.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/versioner/accept_version_header.rb | lib/grape/middleware/versioner/accept_version_header.rb | # 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... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/versioner/base.rb | lib/grape/middleware/versioner/base.rb | # frozen_string_literal: true
module Grape
module Middleware
module Versioner
class Base < Grape::Middleware::Base
DEFAULT_OPTIONS = {
pattern: /.*/i,
prefix: nil,
mount_path: nil,
version_options: {
strict: false,
cascade: true,
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/middleware/versioner/header.rb | lib/grape/middleware/versioner/header.rb | # 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
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/formatter/txt.rb | lib/grape/formatter/txt.rb | # frozen_string_literal: true
module Grape
module Formatter
class Txt < Base
def self.call(object, _env)
object.respond_to?(:to_txt) ? object.to_txt : object.to_s
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/formatter/xml.rb | lib/grape/formatter/xml.rb | # frozen_string_literal: true
module Grape
module Formatter
class Xml < Base
def self.call(object, _env)
return object.to_xml if object.respond_to?(:to_xml)
raise Grape::Exceptions::InvalidFormatter.new(object.class, 'xml')
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/formatter/json.rb | lib/grape/formatter/json.rb | # frozen_string_literal: true
module Grape
module Formatter
class Json < Base
def self.call(object, _env)
return object.to_json if object.respond_to?(:to_json)
::Grape::Json.dump(object)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/formatter/base.rb | lib/grape/formatter/base.rb | # frozen_string_literal: true
module Grape
module Formatter
class Base
def self.call(_object, _env)
raise NotImplementedError
end
def self.inherited(klass)
super
Formatter.register(klass)
end
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/formatter/serializable_hash.rb | lib/grape/formatter/serializable_hash.rb | # frozen_string_literal: true
module Grape
module Formatter
class SerializableHash < Base
class << self
def call(object, _env)
return object if object.is_a?(String)
return ::Grape::Json.dump(serialize(object)) if serializable?(object)
return object.to_json if object.re... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/lib/grape/dsl/desc.rb | lib/grape/dsl/desc.rb | # frozen_string_literal: true
module Grape
module DSL
module Desc
extend Grape::DSL::Settings
# Add a description to the next namespace or function.
# @param description [String] descriptive string for this endpoint
# or namespace
# @param options [Hash] other properties you can ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.