Class: Crane::Engine

Inherits:
Shell::Run show all
Includes:
Config
Defined in:
lib/crane/crane.rb

Direct Known Subclasses

Commands::Init, Commands::Push, Commands::Test

Instance Method Summary collapse

Methods included from Config

get_ignored_files, has_config_file?, load_config, make_config, save_config

Constructor Details

#initialize(argv = []) ⇒ Engine

options



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/crane/crane.rb', line 14

def initialize argv = []
  return true if defined? TESTING
  require File.expand_path("../ftp.rb", __FILE__)
  
  super argv
  @ftp = nil
  @config = Config.load_config
  @ignored_files = get_ignored_files
  @local_files = []
  
  @errors = []
  @connection = nil
  
  (help; exit) if ["help", "h"].any? { |e| true if Shell::Parser.get_options(@argv).include? e }
  (version; exit) if ["version", "v"].any? { |e| true if Shell::Parser.get_options(@argv).include? e }
  
  begin
    run unless defined? TESTING
  rescue Interrupt
    puts "\n"
  rescue
    
  end
end

Instance Method Details

#connect_ftpObject

return an instance of a FTP connection



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
# File 'lib/crane/crane.rb', line 40

def connect_ftp
  require "net/ftp"
  require 'timeout'
  result = true
  
  if @connection.nil? then
    host = @config['ftp']['host_address']
    username = @config['ftp']['username']
    password = @config['ftp']['password']
    @connection = Net::FTP.new
    @connection.passive = true
    begin
      Timeout.timeout(7) do
        @connection.connect host, 21
      end
    rescue
      @connection_error = "couldn't connect to host"
      result = false
    end
    
    begin
      Timeout.timeout(4) do
        @connection. username, password
      end
    rescue
      @connection_error = "invalid username/password"
      result = false
    end
  end
  
  if result == false
    @connection = false
  end
    
  @connection
  
end

#get_ignored_filesObject



83
84
85
86
# File 'lib/crane/crane.rb', line 83

def get_ignored_files
  require File.expand_path("../config.rb", __FILE__);
  Config.get_ignored_files || []
end

#helpObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/crane/crane.rb', line 97

def help
  print "Usage:\n"
  print "\s\scrane COMMAND [options]"
  print "\n\n"
  print "Commands available:"
  print "\n"
  print "\s\spush\t\tSend files to a remote server"
  print "\n\n"
  print "Examples:"
  print "\n"
  print "\s\scrane push 1h"
  print "\n"
  print "\t\tPushes all files modified in the last hour.\n"
  print "\n"
  print "For more information, try:\n"
  print "\s\scrane COMMAND -h"
  print "\n"
end

#is_option(option) ⇒ Object

if there was typed any argument on ARGV starting with either – or -



79
80
81
# File 'lib/crane/crane.rb', line 79

def is_option option
  Shell::Parser.is_option option, @argv
end

#no_commandObject



88
89
90
# File 'lib/crane/crane.rb', line 88

def no_command
  help
end

#versionObject



92
93
94
95
# File 'lib/crane/crane.rb', line 92

def version
  require "crane/version"
  print "Crane v" + Crane::VERSION + "\n"
end