Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Try this.

  • Loading branch information...
commit 46dbd1955782315c34070b79eb2eece378b0fd90 1 parent 1fee516
@kjwierenga authored
Showing with 45 additions and 47 deletions.
  1. +45 −47 lib/guard/s3.rb
View
92 lib/guard/s3.rb
@@ -8,60 +8,58 @@
require 'guard'
require 'guard/guard'
-module ::Guard
- class ::S3 < Guard
- include AWS::S3
- attr_reader :s3_connection, :pwd
+class Guard::S3 < Guard
+ include AWS::S3
+ attr_reader :s3_connection, :pwd
- def initialize(watchers = [], options = {})
- super
- @s3_connection = Base.establish_connection!(
- :access_key_id => options[:access_key_id],
- :secret_access_key => options[:secret_access_key]
- )
- @bucket = options[:bucket]
- @s3_permissions = options[:s3_permissions]
- @extra_headerts = options[:extra_headers]
- @debug = true
- @pwd = watchdir || Dir.pwd
- end
-
- def run_on_change(paths)
- paths.each do |path|
- file = File.join(pwd, path)
- begin
- if exists?(path)
- log "Nothing uploaded. #{path} already exists!"
- else
- log "Uploading #{path}"
- AWS::S3::S3Object.store(path, open(file), @bucket, {
- :access => @s3_permissions
- }.merge(:extra_headers))
- end
- rescue Exception => e
- log e.message
+ def initialize(watchers = [], options = {})
+ super
+ @s3_connection = Base.establish_connection!(
+ :access_key_id => options[:access_key_id],
+ :secret_access_key => options[:secret_access_key]
+ )
+ @bucket = options[:bucket]
+ @s3_permissions = options[:s3_permissions]
+ @extra_headerts = options[:extra_headers]
+ @debug = true
+ @pwd = watchdir || Dir.pwd
+ end
+
+ def run_on_change(paths)
+ paths.each do |path|
+ file = File.join(pwd, path)
+ begin
+ if exists?(path)
+ log "Nothing uploaded. #{path} already exists!"
+ else
+ log "Uploading #{path}"
+ AWS::S3::S3Object.store(path, open(file), @bucket, {
+ :access => @s3_permissions
+ }.merge(:extra_headers))
end
+ rescue Exception => e
+ log e.message
end
end
-
- def exists?(filename)
- filename.nil? ? false : AWS::S3::S3Object.exists?(filename, @bucket)
- end
+ end
+
+ def exists?(filename)
+ filename.nil? ? false : AWS::S3::S3Object.exists?(filename, @bucket)
+ end
- private
+ private
- def debug?
- @debug || false
- end
+ def debug?
+ @debug || false
+ end
- def log(msg)
- return unless debug?
- puts "[#{Time.now}] #{msg}"
- end
+ def log(msg)
+ return unless debug?
+ puts "[#{Time.now}] #{msg}"
+ end
- def watchdir
- # TODO: Nicer way to detect Guard watching a directory explicitly?
- ::Guard::Dsl.send(:class_variable_get, :@@options).watchdir
- end
+ def watchdir
+ # TODO: Nicer way to detect Guard watching a directory explicitly?
+ ::Guard::Dsl.send(:class_variable_get, :@@options).watchdir
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.