module VersionCake::ControllerAdditions
Public Instance Methods
is_deprecated_version?()
click to toggle source
A boolean check to determine if the version requested is deprecated.
# File lib/versioncake/controller_additions.rb, line 29 def is_deprecated_version? version_context.result == :deprecated end
is_latest_version?()
click to toggle source
A boolean check to determine if the latest version is requested.
# File lib/versioncake/controller_additions.rb, line 24 def is_latest_version? version_context.is_latest_version? end
request_version()
click to toggle source
The explicit version requested by a client, this may not be the rendered version and may also be nil.
# File lib/versioncake/controller_additions.rb, line 19 def request_version @request_version ||= version_context.version end
Protected Instance Methods
check_for_version_errors!(result)
click to toggle source
# File lib/versioncake/controller_additions.rb, line 53 def check_for_version_errors!(result) case result when :version_invalid, :version_too_high, :version_too_low, :unknown raise UnsupportedVersionError.new('Unsupported version error') when :obsolete raise ObsoleteVersionError.new('The version given is obsolete') when :no_version unless VersionCake.config.missing_version_use_unversioned_template raise MissingVersionError.new('No version was given') end end end
check_version!(override_version=nil)
click to toggle source
Check the version of the request and raise errors when it's invalid. Additionally, setup view versioning if configured.
@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
# File lib/versioncake/controller_additions.rb, line 46 def check_version!(override_version=nil) return unless version_context check_for_version_errors!(version_context.result) configure_rails_view_versioning(version_context) end
configure_rails_view_versioning(version_context)
click to toggle source
# File lib/versioncake/controller_additions.rb, line 66 def configure_rails_view_versioning(version_context) return unless VersionCake.config.rails_view_versioning if version_context.result == :no_version && VersionCake.config.missing_version_use_unversioned_template lookup_context.versions = nil else lookup_context.versions = version_context.available_versions.map { |n| :"v#{n}" } end end
set_version(version)
click to toggle source
# File lib/versioncake/controller_additions.rb, line 77 def set_version(version) service = VersionCake::VersionContextService.new(VersionCake.config) request.env['versioncake.context'] = service.create_context_from_context(version_context, version) @request_version = version check_version! end
version_context()
click to toggle source
# File lib/versioncake/controller_additions.rb, line 35 def version_context request.env['versioncake.context'] end