Sha256: 08ded12699b9bdfd271721c04c145afdf9c4723480559f8aafa555d71c07fc18

Contents?: true

Size: 1.66 KB

Versions: 22

Compression:

Stored size: 1.66 KB

Contents

module Hanami
  module Action
    # Glue code for full stack Hanami applications
    #
    # This includes missing rendering logic that it makes sense to include
    # only for web applications.
    #
    # @api private
    # @since 0.3.0
    module Glue
      # Rack environment key that indicates where the action instance is passed
      #
      # @api private
      # @since 0.3.0
      ENV_KEY = 'hanami.action'.freeze

      # @api private
      # @since 0.3.2
      ADDITIONAL_HTTP_STATUSES_WITHOUT_BODY = Set.new([301, 302]).freeze

      # Override Ruby's Module#included
      #
      # @api private
      # @since 0.3.0
      def self.included(base)
        base.class_eval { _expose(:format) if respond_to?(:_expose) }
      end

      # Check if the current HTTP request is renderable.
      #
      # It verifies if the verb isn't HEAD, if the status demands to omit
      # the body and if it isn't sending a file.
      #
      # @return [TrueClass,FalseClass] the result of the check
      #
      # @api private
      # @since 0.3.2
      def renderable?
        !_requires_no_body? &&
          !sending_file?    &&
          !ADDITIONAL_HTTP_STATUSES_WITHOUT_BODY.include?(@_status)
      end

      protected
      # Put the current instance into the Rack environment
      #
      # @api private
      # @since 0.3.0
      #
      # @see Hanami::Action#finish
      def finish
        super
        @_env[ENV_KEY] = self
      end

      # Check if the request's body is a file
      #
      # @return [TrueClass,FalseClass] the result of the check
      #
      # @since 0.4.3
      def sending_file?
        @_body.is_a?(::Rack::File::Iterator)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hanami-controller-1.3.3 lib/hanami/action/glue.rb
hanami-controller-1.3.2 lib/hanami/action/glue.rb
hanami-controller-1.3.1 lib/hanami/action/glue.rb
hanami-controller-1.3.0 lib/hanami/action/glue.rb
hanami-controller-1.3.0.beta1 lib/hanami/action/glue.rb
hanami-controller-1.2.0 lib/hanami/action/glue.rb
hanami-controller-1.2.0.rc2 lib/hanami/action/glue.rb
hanami-controller-1.2.0.rc1 lib/hanami/action/glue.rb
hanami-controller-1.2.0.beta2 lib/hanami/action/glue.rb
hanami-controller-1.2.0.beta1 lib/hanami/action/glue.rb
hanami-controller-1.1.1 lib/hanami/action/glue.rb
hanami-controller-1.1.0 lib/hanami/action/glue.rb
hanami-controller-1.1.0.rc1 lib/hanami/action/glue.rb
hanami-controller-1.1.0.beta3 lib/hanami/action/glue.rb
hanami-controller-1.1.0.beta2 lib/hanami/action/glue.rb
hanami-controller-1.1.0.beta1 lib/hanami/action/glue.rb
hanami-controller-1.0.1 lib/hanami/action/glue.rb
hanami-controller-1.0.0 lib/hanami/action/glue.rb
hanami-controller-1.0.0.rc1 lib/hanami/action/glue.rb
hanami-controller-1.0.0.beta3 lib/hanami/action/glue.rb