Class: Slipcover::DevTools::Replicator

Inherits:
Object
  • Object
show all
Defined in:
lib/slipcover/dev_tools.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Replicator



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/slipcover/dev_tools.rb', line 14

def initialize(opts)
  @source_environment = opts[:source_environment] || "staging"
  @target_environment = opts[:target_environment] || "development"
  @database_name = opts[:database_name]
  @logger = opts[:logger] || Logger.new("/dev/null")

  @source_server = Slipcover::Server.new(Slipcover::Config.yaml_path, source_environment)
  @target_server = Slipcover::Server.new(Slipcover::Config.yaml_path, target_environment)

  @http = HttpAdapter.new
end

Instance Attribute Details

#database_nameObject (readonly)

Returns the value of attribute database_name.



12
13
14
# File 'lib/slipcover/dev_tools.rb', line 12

def database_name
  @database_name
end

#httpObject (readonly)

Returns the value of attribute http.



12
13
14
# File 'lib/slipcover/dev_tools.rb', line 12

def http
  @http
end

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/slipcover/dev_tools.rb', line 12

def logger
  @logger
end

#source_environmentObject (readonly)

Returns the value of attribute source_environment.



10
11
12
# File 'lib/slipcover/dev_tools.rb', line 10

def source_environment
  @source_environment
end

#source_serverObject (readonly)

Returns the value of attribute source_server.



10
11
12
# File 'lib/slipcover/dev_tools.rb', line 10

def source_server
  @source_server
end

#target_environmentObject (readonly)

Returns the value of attribute target_environment.



11
12
13
# File 'lib/slipcover/dev_tools.rb', line 11

def target_environment
  @target_environment
end

#target_serverObject (readonly)

Returns the value of attribute target_server.



11
12
13
# File 'lib/slipcover/dev_tools.rb', line 11

def target_server
  @target_server
end

Instance Method Details

#performObject



26
27
28
29
30
31
32
33
# File 'lib/slipcover/dev_tools.rb', line 26

def perform
  logger.info "Fetching list of #{source_environment} databases#{" containing string \"" + database_name + "\"" if database_name}..."
  logger.info "Replicating these dbs: #{dbs_to_replicate.join(",")}"

  dbs_to_replicate.each_with_index.map do |db, i|
    Thread.new(db, i, &method(:replicate))
  end.map(&:join)
end