Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

More sugar in controller helpers for handling custom version logic? #1

Closed
bwillis opened this Issue · 2 comments

1 participant

@bwillis
Owner

I bump an API version, but I have logic that needs to run for the new version only. There is currently a supported interface with requested_version, but we want to explore some other options that might be a little more elegant.

Example:

class UserController < ApplicationController

  def index
    if requested_version >= 5
      ...
    elsif requested_version >= 3
      ...
    elsif requested_version == 2
      ...
    else
      ...
    end
  end

end
@bwillis
Owner

Moving from conversation over here: 3dbdaf6#commitcomment-1847368
Bundler style

  if api ">= v5"
    ...
  elsif api "v3..v4" # or api(2..4) ?
    ...
  elsif api_v2?
    ...
  else
  end

Arel style

  if api.greater_than(5)
    ... 
  elsif api.between(3).and(4)
    ...
  elsif api.eq(2)
    ...
  else
    ...
  end

Forward/backward compatible dynamic versioners

  if forwards_compatible_from_v5?
    ...
  elsif compatible_from_v3_through_v4?
    ...
  elsif backwards_compatible_from_v2?
    ...
  end

respond_to block

supported_versions = (1..10)
versions_for do |version|
  version.is_v5 # >5
  version.is_v3 # 3,4
  version.is_v1 # 1
end
@bwillis
Owner

Closing until we have a better use case.

@bwillis bwillis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.