Class: Sftp::Sync::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sftp/sync/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_options = {}) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sftp/sync/config.rb', line 8

def initialize(_options = {})
  @options = ActiveSupport::HashWithIndifferentAccess.new(_options)


  #required
  options[:host] = ENV["SFTP_SYNC_HOST"] unless options[:host].present?
  raise "missing host. Set SFTP_SYNC_HOST env." unless options[:host].present?

  options[:username] = ENV["SFTP_SYNC_USERNAME"] unless options[:username].present?
  raise "missing username. Set SFTP_SYNC_USERNAME env." unless options[:username].present?


  #optional
  options[:port] = ENV["SFTP_SYNC_PORT"] unless options[:port].present?
  options[:password] = ENV["SFTP_SYNC_PASSWORD"] unless options[:password].present?



end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/sftp/sync/config.rb', line 7

def options
  @options
end

Instance Method Details

#filterObject



56
57
58
59
60
61
62
63
64
# File 'lib/sftp/sync/config.rb', line 56

def filter
  if options[:filter].present?
    options[:filter]
  elsif File.exist?(".gitignore") && options[:gitignore]
    ".gitignore" 
  else 
    nil
  end
end

#filter?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/sftp/sync/config.rb', line 52

def filter?
  filter.present?
end

#hostObject



29
30
31
# File 'lib/sftp/sync/config.rb', line 29

def host
  options[:host]
end

#output_dirObject



66
67
68
# File 'lib/sftp/sync/config.rb', line 66

def output_dir
  options[:output_dir] || ""
end

#passwordObject



37
38
39
# File 'lib/sftp/sync/config.rb', line 37

def password
  options[:password]
end

#portObject



41
42
43
# File 'lib/sftp/sync/config.rb', line 41

def port
  options[:port]
end

#remove_local?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/sftp/sync/config.rb', line 70

def remove_local?
  options[:remove_local]
end

#sftp_optsObject



45
46
47
48
49
50
# File 'lib/sftp/sync/config.rb', line 45

def sftp_opts 
  {}.tap do |opts|
    opts[:password] = password unless password.nil?
    opts[:port] = port unless port.nil?
  end
end

#usernameObject



33
34
35
# File 'lib/sftp/sync/config.rb', line 33

def username
  options[:username]
end