class Zine::Upload
Deploy changes to a remote host, via SFTP or using the AWS or GitHub API
Public Class Methods
new(build_dir, options, delete_file_array, upload_file_array)
click to toggle source
# File lib/zine/upload.rb, line 11 def initialize(build_dir, options, delete_file_array, upload_file_array) if options['method'] == 'none' @no_upload = true return end @build_dir = build_dir @options = options cred_file = options['credentials'] @credentials = read_credentials(cred_file) @upload_file_array = Set.new(upload_file_array).to_a @delete_file_array = Set.new(delete_file_array).to_a - @upload_file_array end
Public Instance Methods
upload_decision(query_class)
click to toggle source
# File lib/zine/upload.rb, line 24 def upload_decision(query_class) return if @no_upload cli = query_class.new answer = cli.call 'Upload files? (Y/n)' return if answer != 'Y' puts Rainbow('Connecting...').green upload end
Private Instance Methods
aws_upload()
click to toggle source
# File lib/zine/upload.rb, line 49 def aws_upload uploader = Zine::UploaderAWS.new(@build_dir, @options, @credentials, @delete_file_array, @upload_file_array) uploader.upload end
github_upload()
click to toggle source
# File lib/zine/upload.rb, line 58 def github_upload uploader = Zine::UploaderGitHub.new(@build_dir, @options, @credentials, @delete_file_array, @upload_file_array) uploader.upload end
parse_yaml(text, cred_file)
click to toggle source
# File lib/zine/upload.rb, line 35 def parse_yaml(text, cred_file) YAML.safe_load text rescue Psych::Exception puts Rainbow("Could not parse YAML in: #{cred_file}").red { 'username' => '', 'password' => '' } end
read_credentials(cred_file)
click to toggle source
# File lib/zine/upload.rb, line 42 def read_credentials(cred_file) parse_yaml(File.read(cred_file), cred_file) rescue Errno::ENOENT puts Rainbow('Path to upload credentials missing from zine.yaml').red exit end
sftp_upload()
click to toggle source
# File lib/zine/upload.rb, line 67 def sftp_upload uploader = Zine::UploaderSFTP.new(@build_dir, @options, @credentials, @delete_file_array, @upload_file_array) uploader.upload end
upload()
click to toggle source
# File lib/zine/upload.rb, line 76 def upload if @options['method'] == 'aws' aws_upload elsif @options['method'] == 'sftp' sftp_upload elsif @options['method'] == 'github' github_upload else puts Rainbow('Unknown upload option in zine.yaml').red end end