class Keycard::Railtie

Railtie to hook Keycard into Rails applications.

This does three things at present:

1. Loads our rake tasks, so you can run keycard:migrate from the app.
2. Pulls the Rails database information off of the ActiveRecord
   connection and puts it on Keycard::DB.config before any application
   initializers are run.
3. Sets up the Keycard 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

after_blocks() click to toggle source
# File lib/keycard/railtie.rb, line 47
def after_blocks
  @after_blocks ||= []
end
after_initializers(&block) click to toggle source

Register a callback to run after anything in 'config/initializers' runs. The block will get a reference to Keycard::DB.config as its only parameter. Keycard::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/keycard/railtie.rb, line 31
def after_initializers(&block)
  after_blocks << block
end
before_blocks() click to toggle source
# File lib/keycard/railtie.rb, line 43
def before_blocks
  @before_blocks ||= []
end
before_initializers(&block) click to toggle source

Register a callback to run before anything in 'config/initializers' runs. The block will get a reference to Keycard::DB.config as its only parameter.

# File lib/keycard/railtie.rb, line 23
def before_initializers(&block)
  before_blocks << block
end
ready_blocks() click to toggle source
# File lib/keycard/railtie.rb, line 51
def ready_blocks
  @ready_blocks ||= []
end
under_rake!() click to toggle source
# File lib/keycard/railtie.rb, line 55
def under_rake!
  @under_rake = true
end
under_rake?() click to toggle source
# File lib/keycard/railtie.rb, line 59
def under_rake?
  @under_rake ||= false
end
when_keycard_is_ready(&block) click to toggle source

Register a callback to run when Keycard 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/keycard/railtie.rb, line 39
def when_keycard_is_ready(&block)
  ready_blocks << block
end

Public Instance Methods

rake_files() click to toggle source
# File lib/keycard/railtie.rb, line 96
def rake_files
  base = Pathname(__dir__) + '../tasks/'
  [base + 'migrate.rake']
end