Class: Wordmove::Movefile

Inherits:
Object
  • Object
show all
Defined in:
lib/wordmove/movefile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli_options = {}, start_dir = nil, verbose = true) ⇒ Movefile

rubocop:disable Style/OptionalBooleanParameter



9
10
11
12
13
14
15
16
17
18
# File 'lib/wordmove/movefile.rb', line 9

def initialize(cli_options = {}, start_dir = nil, verbose = true) # rubocop:disable Style/OptionalBooleanParameter
  @logger = Logger.new($stdout).tap { |l| l.level = Logger::DEBUG }
  @cli_options = cli_options.deep_symbolize_keys || {}
  @config_file_name = @cli_options.fetch(:config, nil)
  @start_dir = start_dir || current_dir

  @options = fetch(verbose)
             .deep_symbolize_keys!
             .freeze
end

Instance Attribute Details

#cli_optionsObject (readonly)

Returns the value of attribute cli_options.



3
4
5
# File 'lib/wordmove/movefile.rb', line 3

def cli_options
  @cli_options
end

#config_file_nameObject (readonly)

Returns the value of attribute config_file_name.



3
4
5
# File 'lib/wordmove/movefile.rb', line 3

def config_file_name
  @config_file_name
end

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/wordmove/movefile.rb', line 3

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/wordmove/movefile.rb', line 3

def options
  @options
end

#start_dirObject (readonly)

Returns the value of attribute start_dir.



3
4
5
# File 'lib/wordmove/movefile.rb', line 3

def start_dir
  @start_dir
end

Instance Method Details

#environmentObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wordmove/movefile.rb', line 20

def environment
  available_enviroments = extract_available_envs(options)

  if available_enviroments.size > 1 && cli_options[:environment].nil?
    raise(
      UndefinedEnvironment,
      'You need to specify an environment with --environment parameter'
    )
  end

  if cli_options[:environment].present? &&
     !available_enviroments.include?(cli_options[:environment].to_sym)
    raise UndefinedEnvironment, "No environment found for \"#{options[:environment]}\". " \
                                "Available Environments: #{available_enviroments.join(' ')}"
  end

  # NOTE: This is Hash#fetch, not self.fetch.
  cli_options.fetch(:environment, available_enviroments.first).to_sym
end

#secretsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/wordmove/movefile.rb', line 40

def secrets
  secrets = []
  options.each_key do |env|
    secrets << options.dig(env, :database, :password)
    secrets << options.dig(env, :database, :host)
    secrets << options.dig(env, :vhost)
    secrets << options.dig(env, :ssh, :password)
    secrets << options.dig(env, :ssh, :host)
    secrets << options.dig(env, :ftp, :password)
    secrets << options.dig(env, :ftp, :host)
    secrets << options.dig(env, :wordpress_path)
  end

  secrets.compact.delete_if(&:empty?)
end