Class: Keycard::Railtie

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

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.after_blocksObject



47
48
49
# File 'lib/keycard/railtie.rb', line 47

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 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.



31
32
33
# File 'lib/keycard/railtie.rb', line 31

def after_initializers(&block)
  after_blocks << block
end

.before_blocksObject



43
44
45
# File 'lib/keycard/railtie.rb', line 43

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 Keycard::DB.config as its only parameter.



23
24
25
# File 'lib/keycard/railtie.rb', line 23

def before_initializers(&block)
  before_blocks << block
end

.ready_blocksObject



51
52
53
# File 'lib/keycard/railtie.rb', line 51

def ready_blocks
  @ready_blocks ||= []
end

.under_rake!Object



55
56
57
# File 'lib/keycard/railtie.rb', line 55

def under_rake!
  @under_rake = true
end

.under_rake?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/keycard/railtie.rb', line 59

def under_rake?
  @under_rake ||= false
end

.when_keycard_is_ready(&block) ⇒ Object

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.



39
40
41
# File 'lib/keycard/railtie.rb', line 39

def when_keycard_is_ready(&block)
  ready_blocks << block
end

Instance Method Details

#rake_filesObject



96
97
98
99
# File 'lib/keycard/railtie.rb', line 96

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