Class: Crane::Engine
- Inherits:
-
Shell::Run
- Object
- Shell::Run
- Crane::Engine
- Includes:
- Config
- Defined in:
- lib/crane/crane.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#connect_ftp ⇒ Object
return an instance of a FTP connection.
- #get_ignored_files ⇒ Object
- #help ⇒ Object
-
#initialize(argv = []) ⇒ Engine
constructor
options.
-
#is_option(option) ⇒ Object
if there was typed any argument on ARGV starting with either – or -.
- #no_command ⇒ Object
- #version ⇒ Object
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.("../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.(@argv).include? e } (version; exit) if ["version", "v"].any? { |e| true if Shell::Parser.(@argv).include? e } begin run unless defined? TESTING rescue Interrupt puts "\n" rescue end end |
Instance Method Details
#connect_ftp ⇒ Object
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.login username, password end rescue @connection_error = "invalid username/password" result = false end end if result == false @connection = false end @connection end |
#get_ignored_files ⇒ Object
83 84 85 86 |
# File 'lib/crane/crane.rb', line 83 def get_ignored_files require File.("../config.rb", __FILE__); Config.get_ignored_files || [] end |
#help ⇒ Object
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_command ⇒ Object
88 89 90 |
# File 'lib/crane/crane.rb', line 88 def no_command help end |