Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bwillis opened this issue Sep 14, 2012 · 2 comments
Closed

Comments

@bwillis
Copy link
Owner

bwillis commented Sep 14, 2012

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
Copy link
Owner Author

bwillis commented Sep 14, 2012

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
Copy link
Owner Author

bwillis commented Nov 11, 2012

Closing until we have a better use case.

@bwillis bwillis closed this as completed Nov 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant