Class: Checkpoint::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/checkpoint/railtie.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.after_blocksObject



48
49
50
# File 'lib/checkpoint/railtie.rb', line 48

def after_blocks
  @after_blocks ||= []
end

.after_initializers(&block) ⇒ Object

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.



32
33
34
# File 'lib/checkpoint/railtie.rb', line 32

def after_initializers(&block)
  after_blocks << block
end

.before_blocksObject



44
45
46
# File 'lib/checkpoint/railtie.rb', line 44

def before_blocks
  @before_blocks ||= []
end

.before_initializers(&block) ⇒ Object

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.



24
25
26
# File 'lib/checkpoint/railtie.rb', line 24

def before_initializers(&block)
  before_blocks << block
end

.ready_blocksObject



52
53
54
# File 'lib/checkpoint/railtie.rb', line 52

def ready_blocks
  @ready_blocks ||= []
end

.under_rake!Object



56
57
58
# File 'lib/checkpoint/railtie.rb', line 56

def under_rake!
  @under_rake = true
end

.under_rake?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/checkpoint/railtie.rb', line 60

def under_rake?
  @under_rake ||= false
end

.when_checkpoint_is_ready(&block) ⇒ Object

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.



40
41
42
# File 'lib/checkpoint/railtie.rb', line 40

def when_checkpoint_is_ready(&block)
  ready_blocks << block
end

Instance Method Details

#rake_filesObject



97
98
99
100
# File 'lib/checkpoint/railtie.rb', line 97

def rake_files
  base = Pathname(__dir__) + '../tasks/'
  [base + 'migrate.rake']
end