Class: MiniDeploy::Processor
- Inherits:
-
Object
- Object
- MiniDeploy::Processor
- Defined in:
- lib/mini_deploy/processor.rb
Instance Method Summary collapse
- #check_file ⇒ Object
- #find_file_content ⇒ Object
-
#initialize(console, original_script, host_data, receipt_data) ⇒ Processor
constructor
A new instance of Processor.
- #remove_file ⇒ Object
- #script_tag ⇒ Object
- #script_type ⇒ Object
- #send_http_request ⇒ Object
- #upload_file ⇒ Object
Constructor Details
#initialize(console, original_script, host_data, receipt_data) ⇒ Processor
Returns a new instance of Processor.
5 6 7 8 9 10 11 12 13 |
# File 'lib/mini_deploy/processor.rb', line 5 def initialize(console, original_script, host_data, receipt_data) @console = console @script = marshal_copy(original_script) @host_data = host_data @receipt_data = receipt_data @ftp = nil create_ftp_client_connect if needs_to_create_ftp end |
Instance Method Details
#check_file ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mini_deploy/processor.rb', line 75 def check_file @console.log "Check file on remote server" format_script_data(:remote_file) @console.log "Check \"#{@script[:remote_file]}\"" if @ftp.exists(@script[:remote_file]) @console.done "File is found" else @console.error "File not found" end @ftp.done rescue StandardError => e @console.error "Unable to connect to the remote server" @console.error e. end |
#find_file_content ⇒ Object
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 |
# File 'lib/mini_deploy/processor.rb', line 47 def find_file_content @console.log "Find file on remote server" format_script_data(:remote_file) @console.log "Search \"#{@script[:remote_file]}\" content" temp_file = @ftp.download_to_temp_file(@script[:remote_file]) file_exists = temp_file.nil? != true if file_exists @console.done "File is found" match_content = find_file_content_by_io(temp_file.current_path, filter: @script[:search_content], ignore_case: @script[:ignore_case]) if match_content.nil? @console.error "No match content" else @console.data match_content end else @console.error "File not found" end @ftp.done rescue StandardError => e @console.error e. end |
#remove_file ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/mini_deploy/processor.rb', line 95 def remove_file @console.log "Remove file on remote server" format_script_data(:remote_file) @console.log "Remove \"#{@script[:remote_file]}\"" if @ftp.remove(@script[:remote_file]) @console.done "File is removed." else @console.error "File not found or Can't removed" end @ftp.done rescue StandardError => e @console.error "Unable to connect to the remote server" @console.error e. end |
#script_tag ⇒ Object
15 16 17 |
# File 'lib/mini_deploy/processor.rb', line 15 def script_tag @script[:tag] end |
#script_type ⇒ Object
19 20 21 |
# File 'lib/mini_deploy/processor.rb', line 19 def script_type @script[:process] end |
#send_http_request ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/mini_deploy/processor.rb', line 115 def send_http_request @console.log "Sent http request to remote server" format_script_data(:url) @console.log "url: #{@script[:url]}" if @script[:params].is_a? Hash @script[:params].each do |key, value| if value.is_a? String @script[:params][key] = replace_data(value, @host_data[:info]) end end end http_client = HTTP.headers('user-agent' => @receipt_data[:agent_name]) case @script[:method] when :get @console.data http_client.get(@script[:url], params: @script[:params]).body.to_s when :post @console.data http_client.post(@script[:url], form: @script[:params]).body.to_s else @console.error "Unknown http method" end rescue StandardError => e @console.error "Unable to connect to the remote server" @console.error e. end |
#upload_file ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mini_deploy/processor.rb', line 23 def upload_file @console.log "Upload file to remote server" format_script_data(:upload_local_source, :remote_path) @console.log "Uploading #{@script[:upload_local_source]} " @console.log "to #{@script[:remote_path]} " upload_file_content = replace_data(IO.read(@script[:upload_local_source]), @host_data[:info]) temp_file = TemporaryFile.new temp_file.write upload_file_content @ftp.upload(temp_file.current_path, @script[:remote_path]) @console.done "Upload Successful" temp_file.done @ftp.done rescue StandardError => e @console.error e. end |