guard-s3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
@@ -0,0 +1,24 @@
1
+ # guard-s3
2
+
3
+ guard-s3 is a simple guard library that syncs local directories with S3 as files are changed.
4
+
5
+ # Usage
6
+
7
+ This is a sample Guardfile
8
+
9
+ opts = {
10
+ :access_key_id => 'ACCESS_KEY_ID_XXXXXX',
11
+ :secret_access_key => 'SECRET_ACCESS_KEY_XXXXXXXXXXXXXXXXXXXXXX',
12
+ :bucket => "mybucket",
13
+ :s3_permissions => :public_read
14
+ }
15
+
16
+ guard 's3', opts do
17
+ watch(/.*/)
18
+ end
19
+
20
+
21
+ # Dependencies
22
+
23
+ - guard
24
+ - aws-s3
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'guard/s3/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-s3"
7
+ s.version = Guard::S3::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["James Welsh"]
10
+ s.email = ["james at supermatter dot com"]
11
+ s.homepage = "http://github.com/guard/guard-s3"
12
+ s.summary = %q{A simple guard library for syncing files with s3}
13
+ s.description = %q{A simple guard library for syncing files with s3}
14
+
15
+ s.required_rubygems_version = '>= 1.3.6'
16
+ s.rubyforge_project = "guard-s3"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'aws-s3'
24
+ s.add_dependency 'guard'
25
+ end
@@ -0,0 +1,61 @@
1
+ begin
2
+ require 'aws/s3'
3
+ rescue LoadError => e
4
+ e.message << " (You may need to install the aws-s3 gem)"
5
+ raise e
6
+ end unless defined?(AWS::S3)
7
+
8
+ require 'guard'
9
+ require 'guard/guard'
10
+
11
+ module ::Guard
12
+ class S3 < Guard
13
+ include AWS::S3
14
+ attr_reader :s3_connection, :pwd
15
+
16
+ def initialize(watchers = [], options = {})
17
+ super
18
+ @s3_connection = Base.establish_connection!(
19
+ :access_key_id => options[:access_key_id],
20
+ :secret_access_key => options[:secret_access_key]
21
+ )
22
+ @bucket = options[:bucket]
23
+ @s3_permissions = :public_read
24
+ @debug = true
25
+ @pwd = Dir.pwd
26
+ end
27
+
28
+ def run_on_change(paths)
29
+ paths.each do |path|
30
+ file = File.join(pwd, path)
31
+ begin
32
+ if exists?(file)
33
+ log "Nothing uploaded. #{file} already exists!"
34
+ else
35
+ log "Syncing #{path}"
36
+ S3Object.store(path, open(file), @bucket)
37
+ #S3Object.store(file, open(file), @bucket, {:content_type => file.content_type.to_s.strip, :access => @s3_permissions})
38
+ end
39
+ rescue Exception => e
40
+ log e.message
41
+ end
42
+ end
43
+ end
44
+
45
+ def exists?(filename)
46
+ filename.nil? ? false : AWS::S3::S3Object.exists?(filename, @bucket)
47
+ end
48
+
49
+ private
50
+
51
+ def debug?
52
+ @debug || false
53
+ end
54
+
55
+ def log(msg)
56
+ return unless debug?
57
+ puts "[#{Time.now}] #{msg}"
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ # guard-s3 configuration options
2
+ opts = {
3
+ :access_key_id => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
4
+ :secret_access_key => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
5
+ :bucket => "mybucket",
6
+ :s3_permissions => :public_read
7
+ }
8
+
9
+ guard 's3', opts do
10
+ watch(/.*/)
11
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module S3
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Welsh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-s3
16
+ requirement: &70196145999740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70196145999740
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard
27
+ requirement: &70196145999160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70196145999160
36
+ description: A simple guard library for syncing files with s3
37
+ email:
38
+ - james at supermatter dot com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - guard-s3.gemspec
48
+ - lib/guard/s3.rb
49
+ - lib/guard/s3/templates/Guardfile
50
+ - lib/guard/s3/version.rb
51
+ homepage: http://github.com/guard/guard-s3
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.6
69
+ requirements: []
70
+ rubyforge_project: guard-s3
71
+ rubygems_version: 1.8.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A simple guard library for syncing files with s3
75
+ test_files: []