Sha256: 394bee99fc28c0a158bb2d496cba6b6435b3ad8c58518e8102789a79696be268

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

require 'action_controller'

module VersionCake
  module ControllerAdditions
    extend ActiveSupport::Concern

    # The explicit version requested by a client, this may not
    # be the rendered version and may also be nil.
    attr_accessor :requested_version

    # A boolean check to determine if the latest version is requested.
    attr_accessor :is_latest_version

    # The requested version by a client or if it's nil the latest or default
    # version configured.
    attr_accessor :derived_version

    # set_version is the prepend filter that will determine the version of the
    # requests.
    included do
      prepend_before_filter :set_version
    end

    protected

    # Sets the version of the request as well as several accessor variables.
    #
    # @param override_version a version number to use instead of the one extracted
    #     from the request
    #
    # @return No explicit return, but several attributes are exposed
    def set_version(override_version=nil)
      versioned_request         = VersionCake::VersionedRequest.new(request, override_version)
      @requested_version        = versioned_request.extracted_version
      @derived_version          = versioned_request.version
      @_lookup_context.versions = versioned_request.supported_versions
      @is_latest_version        = versioned_request.is_latest_version
    end
  end
end

ActionController::Base.send(:include, VersionCake::ControllerAdditions)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
versioncake-2.0.0 lib/versioncake/controller_additions.rb
versioncake-1.3.0 lib/versioncake/controller_additions.rb