module Maturate::InstanceMethods

Public Instance Methods

api_version() click to toggle source

The api version of the current request

# File lib/maturate.rb, line 186
def api_version
  version = params[:api_version]
  return current_api_version if version == 'current'
  api_versions.include?(version) ? version : current_api_version
end
api_versions() click to toggle source

Instance-level shortcut for a class-level accessor

# File lib/maturate.rb, line 181
def api_versions
  self.class.api_versions
end
current_api_version() click to toggle source
# File lib/maturate.rb, line 206
def current_api_version
  self.class._current_api_version || api_versions.last
end
skip_versioned_url_generation() click to toggle source

Don't add api_version to the default url params. Do this in a before_action call: Example:

class HumansController < ApplicationController
  before_action :skip_versioned_url_generation, only: :show

  def show
    render location: unversioned_human_path(Human.first)
  end
end
# File lib/maturate.rb, line 202
def skip_versioned_url_generation
  @_skip_versioned_url_generation = true
end

Private Instance Methods

reset_url_versioning() click to toggle source
# File lib/maturate.rb, line 222
def reset_url_versioning
  @_skip_versioned_url_generation = false
end
set_api_version_default_url_param() click to toggle source
# File lib/maturate.rb, line 216
def set_api_version_default_url_param
  return if @_skip_versioned_url_generation
  params = {api_version: api_version}
  self.default_url_options = default_url_options.merge(params)
end
set_api_version_variant() click to toggle source
# File lib/maturate.rb, line 212
def set_api_version_variant
  request.variant = api_version.to_sym
end