Module: Grape::DSL::Callbacks::ClassMethods

Defined in:
lib/grape/dsl/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#after(&block) ⇒ Object

Execute the given block after the endpoint code has run.



45
46
47
# File 'lib/grape/dsl/callbacks.rb', line 45

def after(&block)
  namespace_stackable(:afters, block)
end

#after_validation(&block) ⇒ Object

Execute the given block after validations and coercions, but before any endpoint code.



40
41
42
# File 'lib/grape/dsl/callbacks.rb', line 40

def after_validation(&block)
  namespace_stackable(:after_validations, block)
end

#before(&block) ⇒ Object

Execute the given block before validation, coercion, or any endpoint code is executed.



28
29
30
# File 'lib/grape/dsl/callbacks.rb', line 28

def before(&block)
  namespace_stackable(:befores, block)
end

#before_validation(&block) ⇒ Object

Execute the given block after ‘before`, but prior to validation or coercion.



34
35
36
# File 'lib/grape/dsl/callbacks.rb', line 34

def before_validation(&block)
  namespace_stackable(:before_validations, block)
end

#finally(&block) ⇒ Object

Allows you to specify a something that will always be executed after a call API call. Unlike the ‘after` block, this code will run even on unsuccesful requests. This will make sure that the ApiLogger is opened and close around every request

Examples:

class ExampleAPI < Grape::API
  before do
    ApiLogger.start
  end
  finally do
    ApiLogger.close
  end
end

Parameters:

  • ensured_block (Proc)

    The block to be executed after every api_call



65
66
67
# File 'lib/grape/dsl/callbacks.rb', line 65

def finally(&block)
  namespace_stackable(:finallies, block)
end