class Checkpoint::Railtie
Railtie
to hook Checkpoint
into Rails applications.
This does three things at present:
1. Loads our rake tasks, so you can run checkpoint:migrate from the app. 2. Pulls the Rails database information off of the ActiveRecord connection and puts it on Checkpoint::DB.config before any application initializers are run. 3. Sets up the Checkpoint database connection after application initializers have run, if it has not already been done and we are not running as a Rake task. This condition is key because when we are in rails server or console, we want to initialize!, but when we are in a rake task to update the database, we have to let it connect, but not initialize.
Public Class Methods
# File lib/checkpoint/railtie.rb, line 48 def after_blocks @after_blocks ||= [] end
Register a callback to run after anything in 'config/initializers' runs. The block will get a reference to Checkpoint::DB.config
as its only parameter. Checkpoint::DB.initialize!
will not have been automatically called at this point, so this is an opportunity to do so if an initializer has not.
# File lib/checkpoint/railtie.rb, line 32 def after_initializers(&block) after_blocks << block end
# File lib/checkpoint/railtie.rb, line 44 def before_blocks @before_blocks ||= [] end
Register a callback to run before anything in 'config/initializers' runs. The block will get a reference to Checkpoint::DB.config
as its only parameter.
# File lib/checkpoint/railtie.rb, line 24 def before_initializers(&block) before_blocks << block end
# File lib/checkpoint/railtie.rb, line 52 def ready_blocks @ready_blocks ||= [] end
# File lib/checkpoint/railtie.rb, line 56 def under_rake! @under_rake = true end
# File lib/checkpoint/railtie.rb, line 60 def under_rake? @under_rake ||= false end
Register a callback to run when Checkpoint
is ready and fully initialized. This will happen once in production, and on each request in development. If you need to do something once in development, you can choose between keeping a flag or using the after_initializers.
# File lib/checkpoint/railtie.rb, line 40 def when_checkpoint_is_ready(&block) ready_blocks << block end
Public Instance Methods
# File lib/checkpoint/railtie.rb, line 97 def rake_files base = Pathname(__dir__) + '../tasks/' [base + 'migrate.rake'] end