Class: FtpBrowserApi

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiclious/ftp_browser.rb

Instance Method Summary collapse

Constructor Details

#initialize(options_file, subdir) ⇒ FtpBrowserApi

Returns a new instance of FtpBrowserApi.



8
9
10
11
12
13
14
# File 'lib/graphiclious/ftp_browser.rb', line 8

def initialize(options_file, subdir)
  @options_file = options_file
  @options = load_options
  @options.localDestinationPath = File.join(File.dirname(@options_file), subdir)
  @options.ftpConnectionTimeout = 600 unless @options.ftpConnectionTimeout > 600
  @options.ftpTransferTimeout = 2000 unless @options.ftpTransferTimeout > 2000
end

Instance Method Details

#load_optionsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/graphiclious/ftp_browser.rb', line 22

def load_options
  return PiggyOptions.new unless File.exists?(@options_file)
  begin
    config = File.open(@options_file) { |io| YAML.load(io) }
    if config.class == Array
      options = config.detect{ |entry| entry.class == PiggyOptions }
    else 
      options = config
    end
    options.initializeNilsWithDefault
  rescue StandardError => ex
    puts('Configuration error, options.yaml ignored: ' + ex.message)
    options = PiggyOptions.new
  end
  return options
end

#run(main_win) ⇒ Object



16
17
18
19
20
# File 'lib/graphiclious/ftp_browser.rb', line 16

def run main_win
  uploadDialog = FtpBrowserDialog.new(main_win, @options)
  uploadDialog.execute
  save_options
end

#save_optionsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/graphiclious/ftp_browser.rb', line 39

def save_options
  begin
    if File.exists?(@options_file)
      File.rename(@options_file, "#{@options_file}.bak")
    end
    File.open(@options_file, 'w') { |out|
      YAML.dump(@options, out)
    }
    puts "Options saved to #{@options_file}"
  rescue StandardError => ex
    puts "Options could not be saved to #{@options_file}: " + ex.message
  end
end