Class: Woro::Adapters::Ftp

Inherits:
Base
  • Object
show all
Defined in:
lib/woro/adapters/ftp.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

create_initial_remote_task, #extract_description

Constructor Details

#initialize(options = []) ⇒ Ftp

Returns a new instance of Ftp.



19
20
21
22
23
24
# File 'lib/woro/adapters/ftp.rb', line 19

def initialize(options = [])
  self.host = options['host']
  self.user = options['user']
  self.password = options['password']
  self.folder = options['folder'] || '/'
end

Instance Attribute Details

#folderObject

Returns the value of attribute folder.



5
6
7
# File 'lib/woro/adapters/ftp.rb', line 5

def folder
  @folder
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/woro/adapters/ftp.rb', line 5

def host
  @host
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/woro/adapters/ftp.rb', line 5

def password
  @password
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/woro/adapters/ftp.rb', line 5

def user
  @user
end

Class Method Details

.setupHash

Setup configuration for adapter Highline CLI helpers can be used for interactivity.

Returns:

  • (Hash)

    Configuration options



10
11
12
13
14
15
16
17
# File 'lib/woro/adapters/ftp.rb', line 10

def self.setup
  {
    'host' =>     ask('FTP Host: '),
    'user' =>     ask('FTP User: '),
    'password' => ask('FTP Passwod: '),
    'folder' =>   ask('FTP Folder: ') { |q| q.default = '/' }
  }
end

Instance Method Details

#list_contentsHash

Returns the list of rake files included in the remote collection with their contents.

Returns:

  • (Hash)

    List of files with their contents



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/woro/adapters/ftp.rb', line 39

def list_contents
  {}.tap do |files|
    remote_files do |file|
      ftp.gettextfile(file) do |line, newline|
        content.concat newline ? line + "\n" : line
      end # temporarly downloads the file
      FileUtils.rm file
      files[file] = { data: content }
    end
  end
end

#list_filesArray

Returns the list of rake files included in the remote collection.

Returns:

  • (Array)

    List of files



28
29
30
31
32
33
34
# File 'lib/woro/adapters/ftp.rb', line 28

def list_files
  [].tap do |files|
    remote_files do |file|
      files << file
    end
  end
end

#push(task) ⇒ Object

Push this task’s file content to ftp server. Existing contents by the same #file_name will be overriden.



53
54
55
56
57
58
# File 'lib/woro/adapters/ftp.rb', line 53

def push(task)
  client do |ftp|
    ftp.chdir(folder)
    ftp.put(task.file_path, task.file_name)
  end
end

#raw_url(file_name) ⇒ String

The raw url is for downloading the rake task content via ftp.

Parameters:

  • file_name (String)

    name of the file to retrieve the download url

Returns:

  • (String)

    HTTP-URL of addressed file within the gist collection



63
64
65
# File 'lib/woro/adapters/ftp.rb', line 63

def raw_url(file_name)
  "ftp://#{user}@#{host}#{folder}#{file_name}"
end