Class: ForestLiana::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- ForestLiana::Engine
- Defined in:
- lib/forest_liana/engine.rb
Instance Method Summary collapse
- #configure_forest_cors ⇒ Object
- #database_available? ⇒ Boolean
- #eager_load_active_record_descendants(app) ⇒ Object
- #rake? ⇒ Boolean
Instance Method Details
#configure_forest_cors ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/forest_liana/engine.rb', line 15 def configure_forest_cors begin rack_cors_class = Rack::Cors rack_cors_class = 'Rack::Cors' if Rails::VERSION::MAJOR < 5 config.middleware.insert_before 0, rack_cors_class do 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 exception end end |
#database_available? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/forest_liana/engine.rb', line 39 def database_available? database_available = true begin ActiveRecord::Base.connection_pool.with_connection { |connection| connection.active? } rescue => error database_available = false 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) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/forest_liana/engine.rb', line 52 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 && defined?(Zeitwerk::Loader) Zeitwerk::Loader.eager_load_all else app.eager_load! end end |
#rake? ⇒ Boolean
35 36 37 |
# File 'lib/forest_liana/engine.rb', line 35 def rake? File.basename($0) == 'rake' end |