s3_assets_uploader 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/s3_assets_uploader.rb +5 -0
- data/lib/s3_assets_uploader/config.rb +36 -0
- data/lib/s3_assets_uploader/rake_task.rb +15 -0
- data/lib/s3_assets_uploader/uploader.rb +45 -0
- data/lib/s3_assets_uploader/version.rb +3 -0
- data/s3_assets_uploader.gemspec +26 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11e410f5838a7cabe8b6667af204ec5cc8046d8a
|
4
|
+
data.tar.gz: 72dc8d9467ad12d6d9bc8fdc7f9e629ad22e2bd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41ce122ce3f3ca8e8741918c284d9348d97994b87927b6b3800dbef255aeaf7a1c605da07e574558c2c8c4047477b976a966b5946d2c6eee97c04fa60baa28bb
|
7
|
+
data.tar.gz: 77ea586239f6b7c3168a50982200af7ef013133dbc38020eb8f945339d7b46c16a0d298bff70a6082fda073dba5117f032006c4442b78bd22ed3a6a6cd573b18
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Kohei Suzuki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# S3AssetsUploader
|
2
|
+
|
3
|
+
Upload Rails assets to S3.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 's3_assets_uploader'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install s3_assets_uploader
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In Rakefile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 's3_assets_uploader/rake_task'
|
27
|
+
namespace :assets do
|
28
|
+
S3AssetsUploader::RakeTask.new(:upload) do |config|
|
29
|
+
config.s3_client = Aws::S3::Client.new(region: 'ap-northeast-1')
|
30
|
+
config.bucket = 'some-bucket'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/eagletmt/s3_assets_uploader/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "s3_assets_uploader"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module S3AssetsUploader
|
4
|
+
class Config < Struct.new(:s3_client, :bucket, :assets_path, :assets_prefix)
|
5
|
+
class ValidationError < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
DEFAULT_ASSETS_PATH = 'public/assets'.freeze
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.assets_path = DEFAULT_ASSETS_PATH
|
12
|
+
end
|
13
|
+
|
14
|
+
def assets_path
|
15
|
+
Pathname.new(self[:assets_path])
|
16
|
+
end
|
17
|
+
|
18
|
+
def public_path
|
19
|
+
assets_path.parent
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate!
|
23
|
+
if bucket.nil?
|
24
|
+
raise ValidationError.new('config.bucket must be set')
|
25
|
+
end
|
26
|
+
self.s3_client ||= create_default_client
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def create_default_client
|
33
|
+
Aws::S3::Client.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rake/tasklib'
|
2
|
+
require 's3_assets_uploader/uploader'
|
3
|
+
|
4
|
+
module S3AssetsUploader
|
5
|
+
class RakeTask < Rake::TaskLib
|
6
|
+
include Rake::DSL
|
7
|
+
|
8
|
+
def initialize(name, &block)
|
9
|
+
desc 'Upload assets to S3'
|
10
|
+
task name do
|
11
|
+
Uploader.new(&block).upload
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 's3_assets_uploader/config'
|
2
|
+
|
3
|
+
module S3AssetsUploader
|
4
|
+
class Uploader
|
5
|
+
def initialize(&block)
|
6
|
+
@config = Config.new
|
7
|
+
block.call(@config)
|
8
|
+
@config.validate!
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload
|
12
|
+
upload_path(@config.assets_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def upload_path(path)
|
18
|
+
if path.directory?
|
19
|
+
path.each_child do |c|
|
20
|
+
upload_path(c)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
path.open do |f|
|
24
|
+
@config.s3_client.put_object(
|
25
|
+
body: f,
|
26
|
+
bucket: @config.bucket,
|
27
|
+
key: compute_asset_key(path),
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def compute_asset_key(path)
|
34
|
+
if @config.assets_prefix
|
35
|
+
File.join(@config.assets_prefix, relative_path(path))
|
36
|
+
else
|
37
|
+
relative_path(path).to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def relative_path(path)
|
42
|
+
path.relative_path_from(@config.public_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 's3_assets_uploader/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "s3_assets_uploader"
|
8
|
+
spec.version = S3AssetsUploader::VERSION
|
9
|
+
spec.authors = ["Kohei Suzuki"]
|
10
|
+
spec.email = ["eagletmt@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Upload Rails assets to S3.}
|
13
|
+
spec.description = %q{Upload Rails assets to S3.}
|
14
|
+
spec.homepage = "https://github.com/eagletmt/s3_assets_uploader"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "aws-sdk", ">= 2.0"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", ">= 3.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s3_assets_uploader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kohei Suzuki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Upload Rails assets to S3.
|
70
|
+
email:
|
71
|
+
- eagletmt@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/s3_assets_uploader.rb
|
87
|
+
- lib/s3_assets_uploader/config.rb
|
88
|
+
- lib/s3_assets_uploader/rake_task.rb
|
89
|
+
- lib/s3_assets_uploader/uploader.rb
|
90
|
+
- lib/s3_assets_uploader/version.rb
|
91
|
+
- s3_assets_uploader.gemspec
|
92
|
+
homepage: https://github.com/eagletmt/s3_assets_uploader
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Upload Rails assets to S3.
|
116
|
+
test_files: []
|