Method: SnapshotReload::SnapshotReload#initialize

Defined in:
lib/snapshot_reload.rb

#initialize(config, options = nil) ⇒ SnapshotReload

Returns a new instance of SnapshotReload.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/snapshot_reload.rb', line 25

def initialize(config, options=nil)

  options = Hash.new if options.nil?

  @config = validate_configuration(config)
  @env = validate_environment(options[:env], @config)

  @host = check_field(@config,@env,'host')
  @database = check_field(@config,@env,'database')
  @username = check_field(@config,@env,'username')
  @password = check_field(@config,@env,'password',false)

  @source = validate_source(options[:source])

  if @source.match('^s3://')
    aws = validate_aws(options['aws-conf'],
      options['aws-key'], options['aws-secret'])
    @aws_key = aws[0]
    @aws_secret = aws[1]
  end

  @save_before = options.has_key?(:save)
  @save_file = options[:save].gsub(/[^-_.\/[:alnum:]]*/, '') + ".sql.gz" if @save_before

  @dry_run = options['dry-run'] ||= false

  @verbose = options[:verbose] ||= false
  @quiet = options[:quiet] ||= false

  @verbose = false if @quiet

  @sql_file = ''

  if @verbose
    info("config: #{@config.to_s}")
    info("env: #{@env.to_s}")
    info("host: #{@host.to_s}")
    info("database: #{@database.to_s}")
    info("username: #{@username.to_s}")
    info("password: #{@password.to_s}")
    info("source: #{@source.to_s}")
    info("aws key: #{@aws_key}")
    info("aws secret: #{@aws_secret}")
    info("save before? #{@save_before.to_s}")
    info("save file: #{@save_file}")
    info("dry run: #{@dry_run}")
    info("verbose: #{@verbose}")
    info("quiet: #{@quiet}")
  end

  reload # and here all the magic happens!!  
  
end