Module: TopologicalInventory::Core::ArHelper

Defined in:
lib/topological_inventory/core/ar_helper.rb

Class Method Summary collapse

Class Method Details

.database_yaml_pathObject



4
5
6
# File 'lib/topological_inventory/core/ar_helper.rb', line 4

def self.database_yaml_path
  @database_yaml_path ||= root.join("config", "database.yml")
end

.database_yaml_path=(path) ⇒ Object



8
9
10
# File 'lib/topological_inventory/core/ar_helper.rb', line 8

def self.database_yaml_path=(path)
  @database_yaml_path = path
end

.load_environment!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/topological_inventory/core/ar_helper.rb', line 12

def self.load_environment!
  ENV["RAILS_ENV"] ||= "development"

  require "yaml"
  database_yaml = YAML.load_file(database_yaml_path) if database_yaml_path.exist?

  require "active_record"
  ActiveRecord::Tasks::DatabaseTasks.env = ENV["RAILS_ENV"]
  ActiveRecord::Tasks::DatabaseTasks.database_configuration = database_yaml || {}
  ActiveRecord::Tasks::DatabaseTasks.db_dir = root.join("db")
  ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [root.join("db/migrate")]

  autoload_models

  require "topological_inventory/core/seed_loader"
  ActiveRecord::Tasks::DatabaseTasks.seed_loader = TopologicalInventory::Core::SeedLoader
  ActiveRecord::Tasks::DatabaseTasks.root = root
  ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration

  ActiveRecord::Base.establish_connection(ENV["RAILS_ENV"].to_sym)
end

.rootObject



34
35
36
37
38
39
# File 'lib/topological_inventory/core/ar_helper.rb', line 34

def self.root
  @root ||= begin
    require 'pathname'
    Pathname.new(__dir__).join("../../..").expand_path
  end
end