Class: Wordmove::Hook

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

Defined Under Namespace

Classes: Config, Local, Remote

Class Method Summary collapse

Class Method Details

.loggerObject



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

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

.run(action, step, cli_options) ⇒ Object

rubocop:disable Metrics/MethodLength



8
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
34
35
36
37
38
39
# File 'lib/wordmove/hook.rb', line 8

def self.run(action, step, cli_options)
  movefile = Wordmove::Movefile.new(cli_options[:config])
  options = movefile.fetch(false)
  environment = movefile.environment(cli_options)

  hooks = Wordmove::Hook::Config.new(
    options[environment][:hooks],
    action,
    step
  )

  return if hooks.empty?

  logger.task "Running #{action}/#{step} hooks"

  hooks.all_commands.each do |command|
    case command[:where]
    when 'local'
      Wordmove::Hook::Local.run(command, options[:local], cli_options[:simulate])
    when 'remote'
      if options[environment][:ftp]
        logger.debug "You have configured remote hooks to run over "\
                     "an FTP connection, but this is not possible. Skipping."
        next
      end

      Wordmove::Hook::Remote.run(command, options[environment], cli_options[:simulate])
    else
      next
    end
  end
end