Class: Stealth::Migrations::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/stealth/migrations/configurator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configurator

Returns a new instance of Configurator.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/stealth/migrations/configurator.rb', line 35

def initialize(options = {})
  default_schema = ENV['SCHEMA'] || ActiveRecord::Tasks::DatabaseTasks.schema_file(ActiveRecord::Base.schema_format)
  defaults = {
    config:       "config/database.yml",
    migrate_dir:  "db/migrate",
    seeds:        "db/seeds.rb",
    schema:       default_schema
  }
  @options = defaults.merge(options)

  Rails.application.config.root = Pathname.pwd
  Rails.application.config.paths["config/database"] = config
end

Class Method Details

.environments_config {|proxy| ... } ⇒ Object

Yields:

  • (proxy)


30
31
32
33
# File 'lib/stealth/migrations/configurator.rb', line 30

def self.environments_config
  proxy = InternalConfigurationsProxy.new(load_configurations)
  yield(proxy) if block_given?
end

.load_configurationsObject



23
24
25
26
27
28
# File 'lib/stealth/migrations/configurator.rb', line 23

def self.load_configurations
  self.new
  @env_config ||= Rails.application.config.database_configuration
  ActiveRecord::Base.configurations = @env_config
  @env_config
end

Instance Method Details

#configObject



49
50
51
# File 'lib/stealth/migrations/configurator.rb', line 49

def config
  @options[:config]
end

#config_for(environment) ⇒ Object



69
70
71
# File 'lib/stealth/migrations/configurator.rb', line 69

def config_for(environment)
  config_for_all[environment.to_s]
end

#config_for_allObject



65
66
67
# File 'lib/stealth/migrations/configurator.rb', line 65

def config_for_all
  Configurator.load_configurations.dup
end

#migrate_dirObject



53
54
55
# File 'lib/stealth/migrations/configurator.rb', line 53

def migrate_dir
  @options[:migrate_dir]
end

#schemaObject



61
62
63
# File 'lib/stealth/migrations/configurator.rb', line 61

def schema
  @options[:schema]
end

#seedsObject



57
58
59
# File 'lib/stealth/migrations/configurator.rb', line 57

def seeds
  @options[:seeds]
end