lib/grape/api.rb in grape-1.2.1 vs lib/grape/api.rb in grape-1.2.2

- old
+ new

@@ -4,16 +4,20 @@ 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[define_singleton_method instance_variable_set inspect class is_a? ! kind_of? - respond_to? respond_to_missing? const_defined? const_missing parent - parent_name name equal? to_s parents anonymous?].freeze + NON_OVERRIDABLE = (Class.new.methods + %i[call call!]).freeze class << self attr_accessor :base_instance, :instances + + # Rather than initializing an object of type Grape::API, create an object of type Instance + def new(*args, &block) + base_instance.new(*args, &block) + end + # When inherited, will create a list of all instances (times the API was mounted) # It will listen to the setup required to mount that endpoint, and replicate it on any new instance def inherited(api, base_instance_parent = Grape::API::Instance) api.initial_setup(base_instance_parent) api.override_all_methods! @@ -34,9 +38,18 @@ (base_instance.methods - NON_OVERRIDABLE).each do |method_override| define_singleton_method(method_override) do |*args, &block| add_setup(method_override, *args, &block) end end + end + + # This is the interface point between Rack and Grape; it accepts a request + # from Rack and ultimately returns an array of three values: the status, + # the headers, and the body. See [the rack specification] + # (http://www.rubydoc.info/github/rack/rack/master/file/SPEC) for more. + # NOTE: This will only be called on an API directly mounted on RACK + def call(*args, &block) + base_instance.call(*args, &block) end # Allows an API to itself be inheritable: def make_inheritable(api) # When a child API inherits from a parent API.