class PuppetHerald::App::Configuration
A configuration for application
Public Class Methods
api?(req)
click to toggle source
Is request part of the API @param req [Sinatra::Request] a request to check @return [Boolean] true, if given request point to part of the API
# File lib/puppet-herald/app/configuration.rb, line 46 def api?(req) (req.path.start_with?('/api') || req.path.start_with?('/version.json')) end
configure_app(options = {})
click to toggle source
Configure the application
@param options [Hash] optional parameters @return [nil]
# File lib/puppet-herald/app/configuration.rb, line 24 def configure_app(options = {}) cron = options.fetch(:cron, true) dbmigrate = options.fetch(:dbmigrate, true) setup_database_logger dbmigrate! if dbmigrate enable_cron if cron nil end
deconfigure_app(options = {})
click to toggle source
De-configure the application
@param options [Hash] optional parameters @return [nil]
# File lib/puppet-herald/app/configuration.rb, line 37 def deconfigure_app(options = {}) cron = options.fetch(:cron, true) disable_cron if cron nil end
Private Class Methods
dbmigrate!()
click to toggle source
Migrates a database to state desired for the application
@return [nil]
# File lib/puppet-herald/app/configuration.rb, line 55 def dbmigrate! ActiveRecord::Base.establish_connection(PuppetHerald.database.spec) ActiveRecord::Migrator.up 'db/migrate' ActiveRecord::Base.clear_active_connections! nil end
disable_cron()
click to toggle source
Disable cron in application
# File lib/puppet-herald/app/configuration.rb, line 74 def disable_cron scheduler.shutdown if scheduler.up? PuppetHerald.logger.info 'Scheduler stopped.' end
enable_cron()
click to toggle source
Enable cron in application
# File lib/puppet-herald/app/configuration.rb, line 63 def enable_cron require 'rufus/scheduler' set :scheduler, Rufus::Scheduler.new job = PuppetHerald::PurgeCronJob.new # Run every 30 minutes, by default cron = ENV['PUPPET_HERALD_PURGE_CRON'] || '*/30 * * * *' PuppetHerald.logger.info "Stating scheduler with: `#{cron}`..." scheduler.cron(cron) { job.run! } end
setup_database_logger()
click to toggle source
Sets logger level for database handlers
@return [nil]
# File lib/puppet-herald/app/configuration.rb, line 82 def setup_database_logger ActiveRecord::Base.logger = PuppetHerald.logger nil end