Module: PhobosDBCheckpoint

Defined in:
lib/phobos_db_checkpoint.rb,
lib/phobos_db_checkpoint/cli.rb,
lib/phobos_db_checkpoint/event.rb,
lib/phobos_db_checkpoint/tasks.rb,
lib/phobos_db_checkpoint/handler.rb,
lib/phobos_db_checkpoint/version.rb,
lib/phobos_db_checkpoint/event_actions.rb

Defined Under Namespace

Modules: CLI, Handler, Tasks Classes: Ack, Event

Constant Summary collapse

DEFAULT_DB_DIR =
'db'.freeze
DEFAULT_MIGRATION_PATH =
File.join(DEFAULT_DB_DIR, 'migrate').freeze
DEFAULT_DB_CONFIG_PATH =
'config/database.yml'.freeze
VERSION =
'0.1.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.db_configObject (readonly)

Returns the value of attribute db_config.



17
18
19
# File 'lib/phobos_db_checkpoint.rb', line 17

def db_config
  @db_config
end

.db_config_pathObject

Returns the value of attribute db_config_path.



18
19
20
# File 'lib/phobos_db_checkpoint.rb', line 18

def db_config_path
  @db_config_path
end

.db_dirObject

Returns the value of attribute db_dir.



18
19
20
# File 'lib/phobos_db_checkpoint.rb', line 18

def db_dir
  @db_dir
end

.migration_pathObject

Returns the value of attribute migration_path.



18
19
20
# File 'lib/phobos_db_checkpoint.rb', line 18

def migration_path
  @migration_path
end

Class Method Details

.close_db_connectionObject



36
37
38
39
40
# File 'lib/phobos_db_checkpoint.rb', line 36

def close_db_connection
  connection = ActiveRecord::Base.connection
  connection.disconnect! if connection
rescue ActiveRecord::ConnectionNotEstablished
end

.configureObject



20
21
22
23
24
# File 'lib/phobos_db_checkpoint.rb', line 20

def configure
  load_db_config
  at_exit { PhobosDBCheckpoint.close_db_connection }
  ActiveRecord::Base.establish_connection(db_config)
end

.envObject



26
27
28
# File 'lib/phobos_db_checkpoint.rb', line 26

def env
  ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] ||= 'development'
end

.load_db_configObject



30
31
32
33
34
# File 'lib/phobos_db_checkpoint.rb', line 30

def load_db_config
  @db_config_path ||= DEFAULT_DB_CONFIG_PATH
  configs = YAML.load_file(File.expand_path(@db_config_path))
  @db_config = configs[env]
end

.load_tasksObject



42
43
44
45
46
47
48
49
# File 'lib/phobos_db_checkpoint.rb', line 42

def load_tasks
  @db_dir ||= DEFAULT_DB_DIR
  @migration_path ||= DEFAULT_MIGRATION_PATH
  ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :db_dir) { PhobosDBCheckpoint.db_dir }
  ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :migrations_paths) { [PhobosDBCheckpoint.migration_path] }
  ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :env) { PhobosDBCheckpoint.env }
  require 'phobos_db_checkpoint/tasks'
end