Skip to content
Snippets Groups Projects
Commit 2d9afda9 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

context with env vars

parent e0147b9b
No related branches found
No related tags found
No related merge requests found
......@@ -14,5 +14,15 @@ module ApplicationController::WithContext
end
helper_method :current_website
def is_university?
@is_university ||= !University.with_host(request.host).nil?
end
helper_method :is_university?
def is_website?
@is_website ||= !Features::Websites::Site.with_host(request.host).nil?
end
helper_method :is_website?
end
end
......@@ -6,7 +6,7 @@ module University::WithIdentifier
validates :identifier, presence: true, uniqueness: true
def self.with_host(host)
find_by(identifier: extract_identifier_from(host)) || first
find_by(identifier: extract_identifier_from(host))
end
private
......@@ -16,20 +16,32 @@ module University::WithIdentifier
# Staging osuny.osuny.dev -> osuny
# Dev osuny.osuny -> osuny
def self.extract_identifier_from(host)
host.remove('.osuny.org')
.remove('.osuny.dev')
.remove('.osuny')
host.remove(production_domain)
.remove(staging_domain)
.remove(dev_domain)
end
def self.production_domain
ENV['OSUNY_PRODUCTION'] || '.osuny.org'
end
def self.staging_domain
ENV['OSUNY_STAGING'] || '.osuny.dev'
end
def self.dev_domain
ENV['OSUNY_DEV'] || '.osuny'
end
end
def domain_url
case Rails.env
when 'development'
"http://#{identifier}.osuny:3000"
"http://#{identifier}#{University.dev_domain}:3000"
when 'staging'
"https://#{identifier}.osuny.dev"
"https://#{identifier}#{University.staging_domain}"
when 'production'
"https://#{identifier}.osuny.org"
"https://#{identifier}#{University.production_domain}"
end
end
end
<footer>
<div class="container small">
<%= current_university %>
<p>Is University? <%= is_university? %></p>
<p>Is website? <%= is_website? %></p>
</div>
</footer>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment