Class: BundleDepot::SCPStore

Inherits:
Store
  • Object
show all
Defined in:
lib/bundle_depot/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Store

#with_packing

Constructor Details

#initialize(host, user, password, path = ".") ⇒ SCPStore

Returns a new instance of SCPStore.



35
36
37
38
39
40
# File 'lib/bundle_depot/cache.rb', line 35

def initialize(host, user, password, path = ".")
  @host     = host
  @user     = user
  @password = password
  @path     = path
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



33
34
35
# File 'lib/bundle_depot/cache.rb', line 33

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



33
34
35
# File 'lib/bundle_depot/cache.rb', line 33

def password
  @password
end

#pathObject (readonly)

Returns the value of attribute path.



33
34
35
# File 'lib/bundle_depot/cache.rb', line 33

def path
  @path
end

#userObject (readonly)

Returns the value of attribute user.



33
34
35
# File 'lib/bundle_depot/cache.rb', line 33

def user
  @user
end

Instance Method Details

#cached?(file) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/bundle_depot/cache.rb', line 42

def cached?(file)
  target = File.join(path, File.basename(file))
  output = "false"

  Net::SSH.start(host, user, { password: password}) do |session|
    output = session.exec! "test -e #{target} && echo 'true'"
  end

  output.strip == "true" 
end

#fetch(file, dest_dir) ⇒ Object



60
61
62
63
64
# File 'lib/bundle_depot/cache.rb', line 60

def fetch(file, dest_dir)
  Net::SCP.download!(host, user, File.join(path, file), file, ssh: { password: password })
rescue Net::SCP::Error
  raise BundleNotFound
end

#store(file) ⇒ Object



53
54
55
56
57
58
# File 'lib/bundle_depot/cache.rb', line 53

def store(file)
  Net::SSH.start(host, user, { password: password}) do |session|
    session.exec! "mkdir -p #{path}"
    session.scp.upload! file, File.join(path, File.basename(file))
  end
end