Class: HasHelpers::Application

Inherits:
ApplicationRecord show all
Includes:
Constant
Defined in:
app/models/has_helpers/application.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Constant

included

Class Method Details

.current_application(request = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/has_helpers/application.rb', line 32

def self.current_application(request = nil)
  if ::HasUtils::Env.development? && ENV["APP"] # only for develoopment specify app by environment var. `APP=HQView rails s`. Needed because hqview, advisorshq and agencieshq are in the same project
    lookup(ENV["APP"])
  elsif ::HasUtils::Env.development? && request && (request.host == "localhost" || request.host =~ /\A(192\.168\.|10\.)/)
    port_regex = /:#{request.port}/
    APPLICATIONS.detect { |application| application.url =~ port_regex }
  else # GCP Environments (Production, Staging, Preview & PR)
    begin
      "HasHelpers::Application::#{request.host.split(".")[-2].upcase}".constantize
    rescue NameError
      lookup(project) # needed for when IP is the url (health check and user keying in IP address in the browser address bar / won't work for advisorshq and hqview)
    end
  end
end

.projectObject



28
29
30
# File 'app/models/has_helpers/application.rb', line 28

def self.project
  Rails.application.class.module_parent_name.downcase
end

Instance Method Details

#urlObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/has_helpers/application.rb', line 13

def url
  @url ||= if ENV["ENV_NAME"] && ENV["ENV_NAME"].include?("preview") # remove this if the url for preview below works
    production_url
  else
    case ::HasUtils::Env.current_environment
    when ::HasUtils::Env::PRODUCTION
      production_url
    when ::HasUtils::Env::PREVIEW, ::HasUtils::Env::STAGING
      staging_url
    else
      development_url
    end
  end
end