Class: Wordmove::Deployer::Base

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

Direct Known Subclasses

FTP, SSH

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, options = {}) ⇒ Base

Returns a new instance of Base.



70
71
72
73
74
# File 'lib/wordmove/deployer/base.rb', line 70

def initialize(environment, options = {})
  @environment = environment.to_sym
  @options = options
  @logger = self.class.logger
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



6
7
8
# File 'lib/wordmove/deployer/base.rb', line 6

def environment
  @environment
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/wordmove/deployer/base.rb', line 5

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/wordmove/deployer/base.rb', line 4

def options
  @options
end

Class Method Details

.current_dirObject



53
54
55
# File 'lib/wordmove/deployer/base.rb', line 53

def current_dir
  '.'
end

.deployer_for(cli_options) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wordmove/deployer/base.rb', line 9

def deployer_for(cli_options)
  options = fetch_movefile(cli_options[:config])
  available_enviroments = extract_available_envs(options)
  options.merge!(cli_options).deep_symbolize_keys!

  if available_enviroments.size > 1 && options[:environment].nil?
    raise(
      UndefinedEnvironment,
      "You need to specify an environment with --environment parameter"
    )
  end
  environment = (options[:environment] || available_enviroments.first).to_sym

  return FTP.new(environment, options) if options[environment][:ftp]

  if options[environment][:ssh] && options[:global][:sql_adapter] == 'wpcli'
    return Ssh::WpcliSqlAdapter.new(environment, options)
  end

  if options[environment][:ssh] && options[:global][:sql_adapter] == 'default'
    return Ssh::DefaultSqlAdapter.new(environment, options)
  end

  raise NoAdapterFound, "No valid adapter found."
end

.extract_available_envs(options) ⇒ Object



35
36
37
# File 'lib/wordmove/deployer/base.rb', line 35

def extract_available_envs(options)
  options.keys.map(&:to_sym) - %i[local global]
end

.fetch_movefile(name = nil, start_dir = current_dir) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wordmove/deployer/base.rb', line 39

def fetch_movefile(name = nil, start_dir = current_dir)
  name ||= "Movefile"
  entries = Dir["#{File.join(start_dir, name)}*"]

  if entries.empty?
    raise MovefileNotFound, "Could not find a valid Movefile" if last_dir?(start_dir)
    return fetch_movefile(name, upper_dir(start_dir))
  end

  found = entries.first
  logger.task("Using Movefile: #{found}")
  YAML.safe_load(ERB.new(File.read(found)).result)
end

.last_dir?(directory) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/wordmove/deployer/base.rb', line 57

def last_dir?(directory)
  directory == "/" || File.exist?(File.join(directory, 'wp-config.php'))
end

.loggerObject



65
66
67
# File 'lib/wordmove/deployer/base.rb', line 65

def logger
  Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
end

.upper_dir(directory) ⇒ Object



61
62
63
# File 'lib/wordmove/deployer/base.rb', line 61

def upper_dir(directory)
  File.expand_path(File.join(directory, '..'))
end

Instance Method Details

#exclude_dir_contents(path) ⇒ Object



104
105
106
# File 'lib/wordmove/deployer/base.rb', line 104

def exclude_dir_contents(path)
  "#{path}/*"
end

#pull_dbObject



80
81
82
# File 'lib/wordmove/deployer/base.rb', line 80

def pull_db
  logger.task "Pulling Database"
end

#pull_wordpressObject



119
120
121
122
123
124
125
126
127
128
# File 'lib/wordmove/deployer/base.rb', line 119

def pull_wordpress
  logger.task "Pulling wordpress core"

  local_path = local_options[:wordpress_path]
  remote_path = remote_options[:wordpress_path]
  exclude_wp_content = exclude_dir_contents(remote_wp_content_dir.relative_path)
  exclude_paths = paths_to_exclude.push(exclude_wp_content)

  remote_get_directory(remote_path, local_path, exclude_paths)
end

#push_dbObject



76
77
78
# File 'lib/wordmove/deployer/base.rb', line 76

def push_db
  logger.task "Pushing Database"
end

#push_wordpressObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/wordmove/deployer/base.rb', line 108

def push_wordpress
  logger.task "Pushing wordpress core"

  local_path = local_options[:wordpress_path]
  remote_path = remote_options[:wordpress_path]
  exclude_wp_content = exclude_dir_contents(local_wp_content_dir.relative_path)
  exclude_paths = paths_to_exclude.push(exclude_wp_content)

  remote_put_directory(local_path, remote_path, exclude_paths)
end

#remote_get_directory(directory) ⇒ Object



84
# File 'lib/wordmove/deployer/base.rb', line 84

def remote_get_directory(directory); end

#remote_put_directory(directory) ⇒ Object



86
# File 'lib/wordmove/deployer/base.rb', line 86

def remote_put_directory(directory); end