Class: Backup::Dependency
- Inherits:
-
Object
- Object
- Backup::Dependency
- Extended by:
- CLI
- Defined in:
- lib/backup/dependency.rb
Overview
A little self-contained gem manager for Backup. Rather than specifying hard dependencies in the gemspec, forcing users to install gems they do not want/need, Backup will notify them when a gem has not been installed, or when the gem’s version is incorrect, and provide the command to install the gem. These dependencies are dynamically loaded in the Gemfile
Class Method Summary collapse
-
.all ⇒ Object
Returns a hash of dependencies that Backup requires in order to run every available feature.
-
.load(name) ⇒ Object
Attempts to load the specified gem (by name and version).
Methods included from CLI
Class Method Details
.all ⇒ Object
Returns a hash of dependencies that Backup requires in order to run every available feature
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/backup/dependency.rb', line 17 def self.all { 'fog' => { :require => 'fog', :version => '~> 0.7.0', :for => 'Amazon S3, Rackspace Cloud Files (S3, CloudFiles Storages)' }, 'dropbox' => { :require => 'dropbox', :version => '~> 1.2.3', :for => 'Dropbox Web Service (Dropbox Storage)' }, 'net-sftp' => { :require => 'net/sftp', :version => '~> 2.0.5', :for => 'SFTP Protocol (SFTP Storage)' }, 'net-scp' => { :require => 'net/scp', :version => '~> 1.0.4', :for => 'SCP Protocol (SCP Storage)' }, 'net-ssh' => { :require => 'net/ssh', :version => '~> 2.1.3', :for => 'SSH Protocol (SSH Storage)' }, 'mail' => { :require => 'mail', :version => '~> 2.2.15', :for => 'Sending Emails (Mail Notifier)' }, 'twitter' => { :require => 'twitter', :version => '~> 1.1.2', :for => 'Send Twitter Updates (Twitter Notifier)' } } end |
.load(name) ⇒ Object
Attempts to load the specified gem (by name and version). If the gem with the correct version cannot be found, it’ll display a message to the user with instructions on how to install the required gem
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/backup/dependency.rb', line 67 def self.load(name) begin gem(name, all[name][:version]) require(all[name][:require]) rescue LoadError Backup::Logger.error("Dependency missing. Please install #{name} version #{all[name][:version]} and try again.") puts "\n\s\sgem install #{name} -v '#{all[name][:version]}'\n\n" puts "Dependency required for:" puts "\n\s\s#{all[name][:for]}" puts "\nTrying to install the #{name} gem for you.. please wait." puts "Once installed, retry the backup procedure.\n\n" puts run("#{ utility(:gem) } install #{name} -v '#{all[name][:version]}'") exit end end |