malygos 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bae2234a02c1df62082421a4ee2e466dcb0b078
4
+ data.tar.gz: 195af8415d376a192ab81a30dbd3ccd577e4e94b
5
+ SHA512:
6
+ metadata.gz: f6facc16b9bb26156fc9b365976d28882951814da1bb7001b3dcb282a67a7485aea9310d96a63cd82b8bd113c5e3fbb34dff4807dd99242d594d5ee6946a98af
7
+ data.tar.gz: c0e4f64b84c52268b47c7d92bc3b98dff4f810b87bfd05b0e10f85f188e90f67d69c490c9689cb6139570caf1d1699e06ce695415258a27c98a822ae6b812703
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+
24
+ *.swp *.swo
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in malygos.gemspec
4
+ gemspec
5
+ gem 'aws-sdk', '~> 2.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 akki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Malygos
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'malygos'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install malygos
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/malygos/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ load 'lib/tasks/malygos.rake'
data/lib/malygos.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'malygos/version'
2
+ require 'malygos/malygos'
3
+ require 'malygos/railtie' if defined?(Rails)
@@ -0,0 +1,9 @@
1
+ module Malygos
2
+ class Config
3
+ attr_accessor :config
4
+
5
+ def config
6
+ @config
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,110 @@
1
+ module Malygos
2
+ class << self
3
+ def connect
4
+ @aws_key = YAML.load(File.read("#{Rails.root}/config/malygos.yml"))
5
+
6
+ @connect ||= Aws::S3::Client.new(
7
+ region: @aws_key['region'],
8
+ access_key_id: @aws_key['access_key_id'],
9
+ secret_access_key: @aws_key['secret_access_key']
10
+ )
11
+
12
+ @log = File.open("#{Rails.root}/log/#{Time.now.strftime("%Y-%m-%d")}-malygos.log", "a+")
13
+ end
14
+
15
+ def disconnect
16
+ @log.close
17
+ end
18
+
19
+ def bucket
20
+ @bucket ||= @aws_key['bucket']
21
+ end
22
+
23
+ def acl
24
+ @acl ||= @aws_key['acl']
25
+ end
26
+
27
+ def sync
28
+ puts "Start"
29
+
30
+ local_list = get_local_assets
31
+ remote_list = get_remote_assets
32
+ file_list = local_list - remote_list
33
+
34
+ if file_list == []
35
+ puts("all files updated.")
36
+ return
37
+ end
38
+
39
+ upload_assets(file_list)
40
+
41
+ puts "Success! upload #{file_list.length} files."
42
+ end
43
+
44
+ def delete_all_remote_assets
45
+ list = get_remote_assets
46
+
47
+ success_num = delete_remote_assets(list)
48
+
49
+ puts "delete #{list.length}, success: #{success_num} assets from s3."
50
+ end
51
+
52
+ def upload_assets(file_list)
53
+ file_list.each do |f|
54
+ File.open(f, 'rb') do |file|
55
+ puts File.path(f)
56
+ @connect.put_object(
57
+ bucket: bucket, key: File.path(f), body: file, acl: acl
58
+ )
59
+ end
60
+ log("upload", f)
61
+ end
62
+ end
63
+
64
+ def delete_remote_assets(file_list)
65
+ puts "Start"
66
+ success = 0
67
+
68
+ if file_list == []
69
+ puts("no files to delete")
70
+ return success
71
+ end
72
+
73
+ file_list.each do |f|
74
+ result = @connect.delete_object(
75
+ bucket: bucket, key: File.path(f)
76
+ )
77
+ success += 1 if result.delete_marker == nil
78
+ log("delete", f)
79
+ end
80
+
81
+ success
82
+ end
83
+
84
+ def get_local_assets
85
+ local_file_list = []
86
+ path = "#{Rails.root}/public/**/*"
87
+
88
+ Dir.glob(path) do |fname|
89
+ local_file_list << fname.sub("#{Rails.root}/", "") if File.file?(fname)
90
+ end
91
+
92
+ local_file_list
93
+ end
94
+
95
+ def get_remote_assets
96
+ obj = @connect.list_objects(bucket: bucket)
97
+ remote_file_list = []
98
+
99
+ obj.contents.each do |object|
100
+ remote_file_list << object.key
101
+ end
102
+
103
+ remote_file_list
104
+ end
105
+
106
+ def log(status, body)
107
+ @log.write("#{Time.now} #{status}: #{body}\n")
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,10 @@
1
+ require 'malygos'
2
+ require 'rails'
3
+
4
+ module Malygos
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load "tasks/malygos.rake"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Malygos
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ namespace :malygos do
2
+ desc "Sync your local assets to amazon s3"
3
+ task :sync do
4
+ connect = Malygos.connect
5
+ Malygos.sync
6
+ Malygos.disconnect
7
+ end
8
+
9
+ desc "Delete all remote assets on amazon s3"
10
+ task :delete_remote_assets do
11
+ connect = Malygos.connect
12
+ Malygos.delete_all_remote_assets
13
+ Malygos.disconnect
14
+ end
15
+ end
data/malygos.gemspec ADDED
@@ -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 'malygos/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "malygos"
8
+ spec.version = Malygos::VERSION
9
+ spec.authors = ["Akkiros"]
10
+ spec.email = ["kwj96966@gmail.com"]
11
+ spec.summary = %q{upload rails assets to amazon s3}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "jeweler"
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: malygos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akkiros
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: rspec
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: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email:
71
+ - kwj96966@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/malygos.rb
82
+ - lib/malygos/config.rb
83
+ - lib/malygos/malygos.rb
84
+ - lib/malygos/railtie.rb
85
+ - lib/malygos/version.rb
86
+ - lib/tasks/malygos.rake
87
+ - malygos.gemspec
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: upload rails assets to amazon s3
112
+ test_files: []