Class: BundleDepot::SCPStore
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #cached?(file) ⇒ Boolean
- #fetch(file, dest_dir) ⇒ Object
-
#initialize(host, user, password, path = ".") ⇒ SCPStore
constructor
A new instance of SCPStore.
- #store(file) ⇒ Object
Methods inherited from Store
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
33 34 35 |
# File 'lib/bundle_depot/cache.rb', line 33 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
33 34 35 |
# File 'lib/bundle_depot/cache.rb', line 33 def password @password end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
33 34 35 |
# File 'lib/bundle_depot/cache.rb', line 33 def path @path end |
#user ⇒ Object (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
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 |