Created
March 30, 2016 09:11
-
-
Save jordifierro/1a16e9ca39eb2f502417afc648b20e09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
module Api::V1::Concerns | |
module VersionExpirationHandler | |
extend ActiveSupport::Concern | |
included do | |
before_action :check_expiration! | |
end | |
def api_version | |
self.class.superclass.name.to_s.split('::').second | |
end | |
def expiration_date | |
@expiration_date ||= ENV[api_version + '_EXPIRATION_DATE'] | |
end | |
def check_expiration! | |
render_error(I18n.t('version.expired'), | |
:upgrade_required) unless supported_version? | |
end | |
def supported_version? | |
!expiration_date || Time.zone.today < Date.parse(expiration_date) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment