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
benchmark/large_model.rb
Ruby
mit
9,984
master
8,906
# frozen_string_literal: true # gem 'grape', '=1.0.1' require 'grape' require 'ruby-prof' require 'hashie' class API < Grape::API # include Grape::Extensions::Hash::ParamBuilder # include Grape::Extensions::Hashie::Mash::ParamBuilder rescue_from do |e| warn "\n\n#{e.class} (#{e.message}):\n #{e.backtra...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
benchmark/remounting.rb
Ruby
mit
9,984
master
958
# frozen_string_literal: true $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'grape' require 'benchmark/memory' class VotingApi < Grape::API logger Logger.new($stdout) helpers do def logger VotingApi.logger end end namespace 'votes' do get do logger en...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
benchmark/nested_params.rb
Ruby
mit
9,984
master
779
# frozen_string_literal: true $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'grape' require 'benchmark/ips' class API < Grape::API prefix :api version 'v1', using: :path params do requires :address, type: Hash do requires :street, type: String requires :postal_code,...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
benchmark/simple.rb
Ruby
mit
9,984
master
459
# frozen_string_literal: true $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'grape' require 'benchmark/ips' class API < Grape::API prefix :api version 'v1', using: :path get '/' do 'hello' end end options = { method: Rack::GET } env = Rack::MockRequest.env_for('/api/v1', o...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
benchmark/compile_many_routes.rb
Ruby
mit
9,984
master
382
# frozen_string_literal: true $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'grape' require 'benchmark/ips' class API < Grape::API prefix :api version 'v1', using: :path 2000.times do |index| get "/test#{index}/" do 'hello' end end end Benchmark.ips do |ips| ips....
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape.rb
Ruby
mit
9,984
master
2,793
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/api.rb
Ruby
mit
9,984
master
6,071
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/namespace.rb
Ruby
mit
9,984
master
1,640
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/cookies.rb
Ruby
mit
9,984
master
952
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/declared_params_handler.rb
Ruby
mit
9,984
master
4,371
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/endpoint.rb
Ruby
mit
9,984
master
13,701
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dry_types.rb
Ruby
mit
9,984
master
1,864
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/env.rb
Ruby
mit
9,984
master
574
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/error_formatter.rb
Ruby
mit
9,984
master
379
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/request.rb
Ruby
mit
9,984
master
4,073
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/router.rb
Ruby
mit
9,984
master
5,363
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/parser.rb
Ruby
mit
9,984
master
253
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/formatter.rb
Ruby
mit
9,984
master
360
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/path.rb
Ruby
mit
9,984
master
2,082
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/params_builder.rb
Ruby
mit
9,984
master
304
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/content_types.rb
Ruby
mit
9,984
master
752
# 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: '...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations.rb
Ruby
mit
9,984
master
440
# 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) ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/testing.rb
Ruby
mit
9,984
master
710
# frozen_string_literal: true module Grape module Testing module RunBeforeEach def run self.class.run_before_each(self) super end end module ClassMethods def before_each(&block) raise ArgumentError, 'a block is required' unless block @before_each ||= []...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/reverse_stackable_values.rb
Ruby
mit
9,984
master
291
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/translation.rb
Ruby
mit
9,984
master
1,709
# frozen_string_literal: true module Grape module Util module Translation FALLBACK_LOCALE = :en private_constant :FALLBACK_LOCALE # Sentinel returned by I18n when a key is missing (passed as the default: # value). Using a named class rather than plain Object.new makes it # identifia...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/media_type.rb
Ruby
mit
9,984
master
1,919
# 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.\-_!^]+?)(...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/header.rb
Ruby
mit
9,984
master
272
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/base_inheritable.rb
Ruby
mit
9,984
master
1,214
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/deep_freeze.rb
Ruby
mit
9,984
master
954
# frozen_string_literal: true module Grape module Util module DeepFreeze module_function # Recursively freezes Hash (keys and values), Array (elements), and String # objects. All other types are returned as-is. # # Intentionally left unfrozen: # - Procs / lambdas — may be d...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/inheritable_setting.rb
Ruby
mit
9,984
master
3,730
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/api_description.rb
Ruby
mit
9,984
master
1,133
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/cache.rb
Ruby
mit
9,984
master
277
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/stackable_values.rb
Ruby
mit
9,984
master
812
# frozen_string_literal: true module Grape module Util class StackableValues < BaseInheritable EMPTY = [].freeze # Even if there is no value, an empty (frozen) array will be returned. def [](name) inherited_value = inherited_values[name] new_value = new_values[name] re...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/registry.rb
Ruby
mit
9,984
master
647
# 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:...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/inheritable_values.rb
Ruby
mit
9,984
master
446
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/lazy/base.rb
Ruby
mit
9,984
master
387
# frozen_string_literal: true module Grape module Util module Lazy # Abstract parent for lazy wrappers used by the remount/configuration # machinery. Call sites can type-check with +is_a?(Grape::Util::Lazy::Base)+ # instead of enumerating the concrete subclasses. class Base def to...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/lazy/block.rb
Ruby
mit
9,984
master
372
# frozen_string_literal: true module Grape module Util module Lazy class Block < Base def initialize(&new_block) super() @block = new_block end def evaluate_from(configuration) @block.call(configuration) end def evaluate @blo...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/lazy/value_enumerable.rb
Ruby
mit
9,984
master
920
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/lazy/value_hash.rb
Ruby
mit
9,984
master
433
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/lazy/value.rb
Ruby
mit
9,984
master
653
# frozen_string_literal: true module Grape module Util module Lazy class Value < Base attr_reader :access_keys def initialize(value, access_keys = []) super() @value = value @access_keys = access_keys end def evaluate_from(configuration) ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/util/lazy/value_array.rb
Ruby
mit
9,984
master
396
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/base.rb
Ruby
mit
9,984
master
1,190
# frozen_string_literal: true module Grape module Exceptions class Base < StandardError include Grape::Util::Translation MESSAGE_STEPS = %w[problem summary resolution].to_h { |s| [s, s.capitalize] }.freeze attr_reader :status, :headers def initialize(status: nil, message: nil, headers:...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/invalid_with_option_for_represent.rb
Ruby
mit
9,984
master
236
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/validation_errors.rb
Ruby
mit
9,984
master
1,288
# frozen_string_literal: true module Grape module Exceptions class ValidationErrors < Base include Enumerable attr_reader :errors def initialize(errors: [], headers: {}) @errors = errors.group_by(&:params) super(message: full_messages.join(', '), status: 400, headers:) e...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/invalid_accept_header.rb
Ruby
mit
9,984
master
265
# frozen_string_literal: true module Grape module Exceptions class InvalidAcceptHeader < Base def initialize(message, headers) super(message: compose_message(:invalid_accept_header, message:), status: 406, headers:) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/validation.rb
Ruby
mit
9,984
master
1,094
# frozen_string_literal: true module Grape module Exceptions class Validation < Base EMPTY_BACKTRACE = [].freeze attr_reader :params, :message_key def initialize(params:, message: nil, status: nil, headers: nil) @params = Array(params) if message @message_key = case ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/validation_array_errors.rb
Ruby
mit
9,984
master
388
# frozen_string_literal: true module Grape module Exceptions class ValidationArrayErrors < Base EMPTY_BACKTRACE = [].freeze attr_reader :errors def initialize(errors) super() @errors = errors # Skip backtrace capture — see Grape::Exceptions::Validation for rationale. ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/invalid_formatter.rb
Ruby
mit
9,984
master
245
# frozen_string_literal: true module Grape module Exceptions class InvalidFormatter < Base def initialize(klass, to_format) super(message: compose_message(:invalid_formatter, klass:, to_format:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/missing_mime_type.rb
Ruby
mit
9,984
master
231
# frozen_string_literal: true module Grape module Exceptions class MissingMimeType < Base def initialize(new_format) super(message: compose_message(:missing_mime_type, new_format:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/incompatible_option_values.rb
Ruby
mit
9,984
master
296
# 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:, value1:, option2:, value2:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/unknown_parameter.rb
Ruby
mit
9,984
master
222
# frozen_string_literal: true module Grape module Exceptions class UnknownParameter < Base def initialize(param) super(message: compose_message(:unknown_parameter, param:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/invalid_message_body.rb
Ruby
mit
9,984
master
252
# frozen_string_literal: true module Grape module Exceptions class InvalidMessageBody < Base def initialize(body_format) super(message: compose_message(:invalid_message_body, body_format:), status: 400) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/invalid_versioner_option.rb
Ruby
mit
9,984
master
241
# frozen_string_literal: true module Grape module Exceptions class InvalidVersionerOption < Base def initialize(strategy) super(message: compose_message(:invalid_versioner_option, strategy:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/request_error.rb
Ruby
mit
9,984
master
210
# frozen_string_literal: true module Grape module Exceptions class RequestError < Base def initialize(status: 400) super(message: $ERROR_INFO&.message, status:) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/unknown_validator.rb
Ruby
mit
9,984
master
240
# frozen_string_literal: true module Grape module Exceptions class UnknownValidator < Base def initialize(validator_type) super(message: compose_message(:unknown_validator, validator_type:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/missing_vendor_option.rb
Ruby
mit
9,984
master
214
# frozen_string_literal: true module Grape module Exceptions class MissingVendorOption < Base def initialize super(message: compose_message(:missing_vendor_option)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/method_not_allowed.rb
Ruby
mit
9,984
master
221
# frozen_string_literal: true module Grape module Exceptions class MethodNotAllowed < Base def initialize(headers) super(message: '405 Not Allowed', status: 405, headers:) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/invalid_version_header.rb
Ruby
mit
9,984
master
267
# frozen_string_literal: true module Grape module Exceptions class InvalidVersionHeader < Base def initialize(message, headers) super(message: compose_message(:invalid_version_header, message:), status: 406, headers:) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/missing_group_type.rb
Ruby
mit
9,984
master
208
# frozen_string_literal: true module Grape module Exceptions class MissingGroupType < Base def initialize super(message: compose_message(:missing_group_type)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/invalid_response.rb
Ruby
mit
9,984
master
205
# frozen_string_literal: true module Grape module Exceptions class InvalidResponse < Base def initialize super(message: compose_message(:invalid_response)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/unknown_params_builder.rb
Ruby
mit
9,984
master
259
# 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:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/unknown_auth_strategy.rb
Ruby
mit
9,984
master
236
# frozen_string_literal: true module Grape module Exceptions class UnknownAuthStrategy < Base def initialize(strategy:) super(message: compose_message(:unknown_auth_strategy, strategy:)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/exceptions/unsupported_group_type.rb
Ruby
mit
9,984
master
216
# frozen_string_literal: true module Grape module Exceptions class UnsupportedGroupType < Base def initialize super(message: compose_message(:unsupported_group_type)) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/parser/base.rb
Ruby
mit
9,984
master
260
# frozen_string_literal: true module Grape module Parser class Base def self.call(_object, _env) raise NotImplementedError end def self.inherited(klass) super Parser.register(klass) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/parser/json.rb
Ruby
mit
9,984
master
380
# frozen_string_literal: true module Grape module Parser class Json < Base def self.call(object, _env) ::Grape::Json.load(object) rescue ::Grape::Json::ParseError # handle JSON parsing errors via the rescue handlers or provide error message raise Grape::Exceptions::InvalidMess...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/parser/xml.rb
Ruby
mit
9,984
master
376
# frozen_string_literal: true module Grape module Parser class Xml < Base def self.call(object, _env) ::Grape::Xml.parse(object) rescue ::Grape::Xml::ParseError # handle XML parsing errors via the rescue handlers or provide error message raise Grape::Exceptions::InvalidMessage...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/callbacks.rb
Ruby
mit
9,984
master
840
# frozen_string_literal: true module Grape module DSL module Callbacks # before: execute the given block before validation, coercion, or any endpoint # before_validation: execute the given block after `before`, but prior to validation or coercion # after_validation: execute the given block afte...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/entity.rb
Ruby
mit
9,984
master
3,721
# frozen_string_literal: true module Grape module DSL module Entity # Allows you to make use of Grape Entities by setting # the response body to the serializable hash of the # entity provided in the `:with` option. This has the # added benefit of automatically passing along environment ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/parameters.rb
Ruby
mit
9,984
master
9,471
# frozen_string_literal: true module Grape module DSL # Defines DSL methods, meant to be applied to a ParamsScope, which define # and describe the parameters accepted by an endpoint, or all endpoints # within a namespace. module Parameters # Set the module used to build the request.params. ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/middleware.rb
Ruby
mit
9,984
master
1,045
# frozen_string_literal: true module Grape module DSL module Middleware # Apply a custom middleware to the API. Applies # to the current namespace and any children, but # not parents. # # @param middleware_class [Class] The class of the middleware you'd like # to inject. ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/desc.rb
Ruby
mit
9,984
master
2,888
# 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 ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/helpers.rb
Ruby
mit
9,984
master
2,674
# frozen_string_literal: true module Grape module DSL module Helpers # Add helper methods that will be accessible from any # endpoint within this namespace (and child namespaces). # # When called without a block, all known helpers within this scope # are included. # # @p...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/settings.rb
Ruby
mit
9,984
master
2,438
# frozen_string_literal: true module Grape module DSL # Keeps track of settings (implemented as key-value pairs, grouped by # types), in two contexts: top-level settings which apply globally no # matter where they're defined, and inheritable settings which apply only # in the current scope and scopes...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/validations.rb
Ruby
mit
9,984
master
1,876
# frozen_string_literal: true module Grape module DSL module Validations # Opens a root-level ParamsScope, defining parameter coercions and # validations for the endpoint. # @yield instance context of the new scope def params(&) Grape::Validations::ParamsScope.new(api: self, type:...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/headers.rb
Ruby
mit
9,984
master
554
# frozen_string_literal: true module Grape module DSL module Headers # This method has four responsibilities: # 1. Set a specifc header value by key # 2. Retrieve a specifc header value by key # 3. Retrieve all headers that have been set # 4. Delete a specifc header key-value pair ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/logger.rb
Ruby
mit
9,984
master
546
# frozen_string_literal: true module Grape module DSL module Logger # Set or retrive the configured logger. If none was configured, this # method will create a new one, logging to stdout. # @param logger [Object] the new logger to use def logger(logger = nil) global_settings = inh...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/inside_route.rb
Ruby
mit
9,984
master
6,313
# frozen_string_literal: true module Grape module DSL module InsideRoute include Declared include Entity # Backward compatibility: alias exception class to previous location MethodNotYetAvailable = Declared::MethodNotYetAvailable # The API version as specified in the URL. de...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/request_response.rb
Ruby
mit
9,984
master
6,650
# frozen_string_literal: true module Grape module DSL module RequestResponse # Specify the default format for the API's serializers. # May be `:json` or `:txt` (default). def default_format(new_format = nil) return inheritable_setting.namespace_inheritable[:default_format] if new_format...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/routing.rb
Ruby
mit
9,984
master
9,354
# frozen_string_literal: true module Grape module DSL module Routing attr_reader :endpoints def given(conditional_option, &) return unless conditional_option mounted(&) end def mounted(&block) evaluate_as_instance_with_configuration(block, lazy: true) end ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/dsl/declared.rb
Ruby
mit
9,984
master
1,805
# frozen_string_literal: true module Grape module DSL module Declared # Denotes a situation where a DSL method has been invoked in a # filter which it should not yet be available in class MethodNotYetAvailable < StandardError def initialize(msg = '#declared is not available prior to par...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/formatter/serializable_hash.rb
Ruby
mit
9,984
master
1,082
# 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...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/formatter/base.rb
Ruby
mit
9,984
master
266
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/formatter/txt.rb
Ruby
mit
9,984
master
212
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/formatter/json.rb
Ruby
mit
9,984
master
245
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/formatter/xml.rb
Ruby
mit
9,984
master
282
# 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
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/router/pattern.rb
Ruby
mit
9,984
master
1,817
# frozen_string_literal: true module Grape class Router class Pattern extend Forwardable DEFAULT_CAPTURES = %w[format version].freeze attr_reader :origin, :path, :pattern, :to_regexp def_delegators :pattern, :params def_delegators :to_regexp, :=== alias match? === de...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/router/greedy_route.rb
Ruby
mit
9,984
master
505
# frozen_string_literal: true # Act like a Grape::Router::Route but for greedy_match # see @neutral_map module Grape class Router class GreedyRoute < BaseRoute extend Forwardable def_delegators :@endpoint, :call attr_reader :endpoint, :allow_header def initialize(pattern, endpoint:, a...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/router/route.rb
Ruby
mit
9,984
master
1,429
# frozen_string_literal: true module Grape class Router class Route < BaseRoute extend Forwardable FORWARD_MATCH_METHOD = ->(input, pattern) { input.start_with?(pattern.origin) } NON_FORWARD_MATCH_METHOD = ->(input, pattern) { pattern.match?(input) } attr_reader :app, :request_method, :...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/router/base_route.rb
Ruby
mit
9,984
master
1,244
# frozen_string_literal: true module Grape class Router class BaseRoute extend Forwardable delegate_missing_to :@options attr_reader :options, :pattern def_delegators :@pattern, :path, :origin def_delegators :@options, :description, :version, :requirements, :prefix, :anchor, :set...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/attributes_iterator.rb
Ruby
mit
9,984
master
2,731
# frozen_string_literal: true module Grape module Validations class AttributesIterator include Enumerable attr_reader :scope def initialize(attrs, scope, params) @attrs = attrs @scope = scope @original_params = scope.params(params) @params = Array.wrap(@origina...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/contract_scope.rb
Ruby
mit
9,984
master
1,069
# frozen_string_literal: true module Grape module Validations class ContractScope # Declare the contract to be used for the endpoint's parameters. # @param api [API] the API endpoint to modify. # @param contract the contract or schema to be used for validation. Optional. # @yield a block ...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/multiple_attributes_iterator.rb
Ruby
mit
9,984
master
270
# frozen_string_literal: true module Grape module Validations class MultipleAttributesIterator < AttributesIterator private def yield_attributes(resource_params) yield resource_params unless skip?(resource_params) end end end end
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/params_scope.rb
Ruby
mit
9,984
master
20,905
# frozen_string_literal: true module Grape module Validations class ParamsScope attr_reader :parent, :type, :nearest_array_ancestor, :full_path def qualifying_params ParamScopeTracker.current&.qualifying_params(self) end include Grape::DSL::Parameters include Grape::Valida...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/types.rb
Ruby
mit
9,984
master
6,957
# frozen_string_literal: true module Grape module Validations # Module for code related to grape's system for # coercion and type validation of incoming request # parameters. # # Grape uses a number of tests and assertions to # work out exactly how a parameter should be handled, # based o...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/param_scope_tracker.rb
Ruby
mit
9,984
master
1,882
# frozen_string_literal: true module Grape module Validations # Holds per-request mutable state that must not live on shared ParamsScope # instances. Both trackers are identity-keyed hashes so that ParamsScope # objects can serve as keys without relying on value equality. # # Lifecycle is managed...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/single_attribute_iterator.rb
Ruby
mit
9,984
master
590
# frozen_string_literal: true module Grape module Validations class SingleAttributeIterator < AttributesIterator private def yield_attributes(val) return if skip?(val) @attrs.each do |attr_name| yield val, attr_name, empty?(val) end end # Primitives li...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/params_documentation.rb
Ruby
mit
9,984
master
1,890
# frozen_string_literal: true module Grape module Validations # Documents parameters of an endpoint. If documentation isn't needed (for instance, it is an # internal API), the class only cleans up attributes to avoid junk in RAM. module ParamsDocumentation def document_params(attrs, validations, t...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/validators/base.rb
Ruby
mit
9,984
master
6,148
# frozen_string_literal: true module Grape module Validations module Validators # Base class for all parameter validators. # # == Freeze contract # Validator instances are shared across requests and are frozen after # initialization (via +.new+). All inputs (+options+, +opts+, +attr...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/validators/same_as_validator.rb
Ruby
mit
9,984
master
480
# frozen_string_literal: true module Grape module Validations module Validators class SameAsValidator < Base def initialize(attrs, options, required, scope, opts) super @value = option_value end def validate_param!(attr_name, params) return if params[a...
github
ruby-grape/grape
https://github.com/ruby-grape/grape
lib/grape/validations/validators/all_or_none_of_validator.rb
Ruby
mit
9,984
master
449
# frozen_string_literal: true module Grape module Validations module Validators class AllOrNoneOfValidator < MultipleParamsBase default_message_key :all_or_none def validate_params!(params) known_keys = all_keys keys = keys_in_common(params, known_keys) return...