Sha256: b1e71c73543fcbb60037eab117171cdecb83a7439e1b3d38b9bf195e6705ca02

Contents?: true

Size: 1.36 KB

Versions: 19

Compression:

Stored size: 1.36 KB

Contents

require 'active_support/concern'

module Grape
  module DSL
    # Blocks can be executed before or after every API call, using `before`, `after`,
    # `before_validation` and `after_validation`.
    #
    # Before and after callbacks execute in the following order:
    #
    # 1. `before`
    # 2. `before_validation`
    # 3. _validations_
    # 4. `after_validation`
    # 5. _the API call_
    # 6. `after`
    #
    # Steps 4, 5 and 6 only happen if validation succeeds.
    module Callbacks
      extend ActiveSupport::Concern

      include Grape::DSL::Configuration

      module ClassMethods
        # Execute the given block before validation, coercion, or any endpoint
        # code is executed.
        def before(&block)
          namespace_stackable(:befores, block)
        end

        # Execute the given block after `before`, but prior to validation or
        # coercion.
        def before_validation(&block)
          namespace_stackable(:before_validations, block)
        end

        # Execute the given block after validations and coercions, but before
        # any endpoint code.
        def after_validation(&block)
          namespace_stackable(:after_validations, block)
        end

        # Execute the given block after the endpoint code has run.
        def after(&block)
          namespace_stackable(:afters, block)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
grape-1.2.3 lib/grape/dsl/callbacks.rb
grape-1.2.2 lib/grape/dsl/callbacks.rb
grape-1.2.1 lib/grape/dsl/callbacks.rb
grape-1.2.0 lib/grape/dsl/callbacks.rb
grape-1.1.0 lib/grape/dsl/callbacks.rb
grape-1.0.3 lib/grape/dsl/callbacks.rb
grape-1.0.2 lib/grape/dsl/callbacks.rb
grape-1.0.1 lib/grape/dsl/callbacks.rb
grape-1.0.0 lib/grape/dsl/callbacks.rb
grape-0.19.2 lib/grape/dsl/callbacks.rb
grape-0.19.1 lib/grape/dsl/callbacks.rb
grape-0.19.0 lib/grape/dsl/callbacks.rb
grape-0.18.0 lib/grape/dsl/callbacks.rb
grape-0.17.0 lib/grape/dsl/callbacks.rb
grape-0.16.2 lib/grape/dsl/callbacks.rb
grape-0.16.1 lib/grape/dsl/callbacks.rb
grape-0.15.0 lib/grape/dsl/callbacks.rb
grape-0.14.0 lib/grape/dsl/callbacks.rb
grape-0.13.0 lib/grape/dsl/callbacks.rb