Module: Frank::Publish

Defined in:
lib/frank/publish.rb,
lib/frank/publish/ftp.rb,
lib/frank/publish/scp.rb,
lib/frank/publish/base.rb,
lib/frank/publish/sftp.rb,
lib/frank/publish/ftptls.rb,
lib/frank/publish/shell_scp.rb

Defined Under Namespace

Classes: Base, FTP, FTPTLS, SCP, SFTP, ShellSCP

Class Method Summary collapse

Class Method Details

.err_message(str, prefix = '') ⇒ Object



69
70
71
# File 'lib/frank/publish.rb', line 69

def self.err_message str, prefix = ''
  puts "#{prefix}\033[31m#{str}\033[0m"
end

.execute!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/frank/publish.rb', line 5

def self.execute!
  protocol = exit_unless_configured.to_s

  ok_message "", "\nFrank is..."
  ok_message "Exporting templates", " - "

  # upload the files and report progress
  ok_message "Publishing to: `#{Frank.publish.host}:#{Frank.publish.path}' via #{protocol}", " - "


  req = "frank/publish/#{protocol.downcase}"
  rescue_load_error protocol do
    require req
    clazz = Frank::Publish.const_get(protocol.upcase)
    publisher = clazz.new(Frank.publish)
    publisher.perform!
  end

  ok_message "\nPublish complete!"
end

.exit_unless_configuredObject



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
# File 'lib/frank/publish.rb', line 26

def self.exit_unless_configured
  required_settings = {:host => Frank.publish.host, :path => Frank.publish.path, :username => Frank.publish.username}

  should_exit = false
  message = ""

  protocol = Frank.publish.mode || :scp
  unless [:ftp, :ftptls, :sftp, :scp].include?(protocol.to_sym)
    message << "Frank.publish.mode = #{protocol} is not supported. Supported publish modes are 'ftp', 'ftptls', 'sftp' or 'scp' (default)\n"
    should_exit = true
  end

  required_settings.each do |name, value|
    if value.nil?
      message << "Frank.publish.#{name} is required to publish. You can configure it in setup.rb\n"
      should_exit = true
    end
  end


  if should_exit
    err_message message
    exit!
  end

  protocol
end

.ok_message(str, prefix = '') ⇒ Object



65
66
67
# File 'lib/frank/publish.rb', line 65

def self.ok_message str, prefix = ''
  puts "#{prefix}\033[32m#{str}\033[0m"
end

.rescue_load_error(protocol, &blk) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/frank/publish.rb', line 54

def self.rescue_load_error protocol, &blk
  gem = "net-#{protocol}"
  begin
    yield
  rescue LoadError
    err_message "Publishing via #{protocol} requires the '#{gem}' gem. `gem install #{gem}'"
    exit!
  end
end