Class: DropboxDeployment::Deployer
- Inherits:
-
Object
- Object
- DropboxDeployment::Deployer
- Defined in:
- lib/dropbox-deployment.rb
Instance Method Summary collapse
- #deploy ⇒ Object
-
#initialize ⇒ Deployer
constructor
A new instance of Deployer.
- #uploadDirectory(dropboxClient, directoryPath, dropboxPath) ⇒ Object
- #uploadFile(dropboxClient, file, dropboxPath) ⇒ Object
Constructor Details
#initialize ⇒ Deployer
Returns a new instance of Deployer.
12 13 14 15 |
# File 'lib/dropbox-deployment.rb', line 12 def initialize @@logger = Logger.new(STDOUT) @@logger.level = Logger::WARN end |
Instance Method Details
#deploy ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dropbox-deployment.rb', line 41 def deploy() # Validation if !File.file?("dropbox-deployment.yml") puts "\nNo config file found. You need a file called `dropbox-deployment.yml` with the configuration. See the README for details\n\n" exit(1) end config = YAML.load_file("dropbox-deployment.yml") testing = false if !config.has_key?("deploy") puts "\nError in config file! Build file must contain a `deploy` object.\n\n" exit(1) end artifactPath = config["deploy"]["artifacts_path"] dropboxPath = config["deploy"]["dropbox_path"] if ENV["DROPBOX_OAUTH_BEARER"].nil? puts "\nYou must have an environment variable of `DROPBOX_OAUTH_BEARER` in order to deploy to Dropbox\n\n" exit(1) end if config["deploy"]["debug"] @@logger.level = Logger::DEBUG @@logger.debug("We are in debug mode") end dropboxClient = DropboxApi::Client.new # Upload all files @@logger.debug("Artifact Path: " + artifactPath) @@logger.debug("Dropbox Path: " + dropboxPath) isDirectory = File.directory?(artifactPath) @@logger.debug("Is directory: " + "#{isDirectory}") if isDirectory uploadDirectory(dropboxClient, artifactPath, dropboxPath) else artifactFile = File.open(artifactPath) uploadFile(dropboxClient, artifactFile, dropboxPath) end @@logger.debug("Uploading complete") end |
#uploadDirectory(dropboxClient, directoryPath, dropboxPath) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dropbox-deployment.rb', line 24 def uploadDirectory(dropboxClient, directoryPath, dropboxPath) Find.find(directoryPath) do |file| if !File.directory?(file) currentFileDir = File.dirname(file) if currentFileDir == directoryPath modifedPath = dropboxPath else # adjust for if we are a subdirectory within the desired saved build folder modifedPath = dropboxPath + "/" + Pathname.new(currentFileDir).relative_path_from(Pathname.new(directoryPath)).to_s end uploadFile(dropboxClient, file, modifedPath) end end end |
#uploadFile(dropboxClient, file, dropboxPath) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/dropbox-deployment.rb', line 17 def uploadFile(dropboxClient, file, dropboxPath) fileName = File.basename(file) content = IO.read(file) @@logger.debug("Uploading " + fileName + " to " + dropboxPath + "/" + fileName) dropboxClient.upload dropboxPath + "/" + fileName, content, :mode => :overwrite end |