class ForestLiana::Engine

Public Instance Methods

configure_forest_cors() click to toggle source
# File lib/forest_liana/engine.rb, line 30
def configure_forest_cors
  begin
    rack_cors_class = Rack::Cors
    rack_cors_class = 'Rack::Cors' if Rails::VERSION::MAJOR < 5
    null_regex = Regexp.new(/\Anull\z/)

    config.middleware.insert_before 0, rack_cors_class do
      allow do
        hostnames = [null_regex, 'localhost:4200', /\A.*\.forestadmin\.com\z/]
        hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']

        origins hostnames
        resource ForestLiana::AuthenticationController::PUBLIC_ROUTES[1], headers: :any, methods: :any, credentials: true, max_age: 86400 # NOTICE: 1 day
      end

      allow do
        hostnames = ['localhost:4200', /\A.*\.forestadmin\.com\z/]
        hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']

        origins hostnames
        resource '*', headers: :any, methods: :any, credentials: true, max_age: 86400 # NOTICE: 1 day
      end
    end
    nil
  rescue => exception
    FOREST_REPORTER.report exception
    exception
  end
end
database_available?() click to toggle source
# File lib/forest_liana/engine.rb, line 64
def database_available?
  database_available = true
  begin
    ActiveRecord::Base.connection_pool.with_connection { |connection| connection.active? }
  rescue => error
    database_available = false
    FOREST_REPORTER.report error
    FOREST_LOGGER.error "No Apimap sent to Forest servers, it seems that the database is not accessible:\n#{error}"
  end
  database_available
end
eager_load_active_record_descendants(app) click to toggle source
# File lib/forest_liana/engine.rb, line 78
def eager_load_active_record_descendants app
  # HACK: Force the ActiveRecord descendants classes from ActiveStorage to load for
  #       introspection.
  if defined? ActiveStorage
    ActiveStorage::Blob
    ActiveStorage::Attachment
  end

  if Rails::VERSION::MAJOR > 5 && Rails.autoloaders.zeitwerk_enabled?
    Zeitwerk::Loader.eager_load_all
  else
    app.eager_load!
  end
end
rake?() click to toggle source
# File lib/forest_liana/engine.rb, line 60
def rake?
  File.basename($0) == 'rake'
end