bundler_cacher 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ tags
20
+ .rvmrc
21
+ config
22
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'aws-sdk'
4
+ gem 'rubyzip'
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ aws-sdk (1.8.0)
5
+ httparty (~> 0.7)
6
+ json (~> 1.4)
7
+ nokogiri (>= 1.4.4)
8
+ uuidtools (~> 2.1)
9
+ httparty (0.9.0)
10
+ multi_json (~> 1.0)
11
+ multi_xml
12
+ json (1.7.5)
13
+ multi_json (1.5.0)
14
+ multi_xml (0.5.1)
15
+ nokogiri (1.5.6)
16
+ rubyzip (0.9.9)
17
+ uuidtools (2.1.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ aws-sdk
24
+ rubyzip
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ bundler_cacher
2
+ ==============
3
+
4
+ Bundler Cacher for RubyGems
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ - specs
2
+ - readme
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Signal.trap("INT") { exit 1 }
4
+
5
+ require 'bundler'
6
+ # Check if an older version of bundler is installed
7
+ $:.each do |path|
8
+ if path =~ %r'/bundler-0.(\d+)' && $1.to_i < 9
9
+ err = "Please remove Bundler 0.8 versions."
10
+ err << "This can be done by running `gem cleanup bundler`."
11
+ abort(err)
12
+ end
13
+ end
14
+
15
+ require 'bundler_cacher'
16
+
17
+ require 'bundler/cli'
18
+ require 'bundler/friendly_errors'
19
+
20
+
21
+ Bundler.with_friendly_errors { Bundler::CLI.start }
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'bundler_cacher/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "bundler_cacher"
9
+ s.version = BundlerCacher::VERSION
10
+ s.platform = Gem::Platform::RUBY
11
+ s.license = "MIT"
12
+ s.authors = ["Bartłomiej Danek"]
13
+ s.email = ["bartek.danek@gmail.com"]
14
+ s.homepage = "https://github.com/bartekd/bundler_cacher"
15
+ s.summary = %q{The best way to cache your gems}
16
+ s.description = %q{}
17
+
18
+ s.required_ruby_version = ">= 1.8.7"
19
+ s.required_rubygems_version = ">= 1.3.6"
20
+
21
+ s.add_dependency 'bundler', '>= 1.2.2'
22
+ s.add_dependency 'rubyzip', '>= 0.9.9'
23
+ s.add_dependency 'aws-sdk', '>= 1.8.0'
24
+
25
+ # Man files are required because they are ignored by git
26
+ git_files = `git ls-files`.split("\n") rescue ''
27
+ s.files = git_files
28
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
+ s.executables = %w(bundler_cacher)
30
+ s.require_paths = ["lib"]
31
+ end
@@ -0,0 +1,3 @@
1
+ module BundlerCacher
2
+ VERSION = "0.0.2" unless defined?(::BundlerCacher::VERSION)
3
+ end
@@ -0,0 +1,100 @@
1
+ require 'yaml'
2
+ require 'aws-sdk'
3
+ require 'zip/zip'
4
+ require 'zip/zipfilesystem'
5
+
6
+ class Bundler::Installer
7
+ class << self
8
+ alias_method :base_install, :install
9
+
10
+ def install(root, definition, options = {})
11
+ fetch_gempack
12
+ rescue AWS::S3::Errors::NoSuchKey
13
+ base_install(root, definition, options)
14
+ push_gempack
15
+ end
16
+
17
+ protected
18
+ def establish_connection_with_s3
19
+ AWS.config({:access_key_id => s3_config["access_key_id"],
20
+ :secret_access_key => s3_config["secret_access_key"]})
21
+ @s3 ||= AWS::S3.new
22
+ @bucket ||= @s3.buckets.find {|bucket| bucket.name == s3_config["bucket"]}
23
+ end
24
+
25
+ def s3_config
26
+ @s3_config ||= YAML.load_file "config/bundler_cacher.yml"
27
+ end
28
+
29
+ private
30
+ def fetch_gempack
31
+ establish_connection_with_s3
32
+ _archive_s3_object = @bucket.objects[archive_name]
33
+ _archive = File.open(tmp_archive, 'w')
34
+ _archive.puts _archive_s3_object.read
35
+ _archive.close
36
+
37
+ extract_gamepack
38
+ end
39
+
40
+ def send_to_s3(file)
41
+ establish_connection_with_s3
42
+ obj = @bucket.objects.create(archive_name,'')
43
+ obj.write(Pathname.new(archive_path))
44
+ end
45
+
46
+ def push_gempack
47
+ archive = compress_gempack
48
+ send_to_s3(archive)
49
+ end
50
+
51
+ def compress_gempack
52
+ FileUtils.rm archive_path, :force => true
53
+ Zip::ZipFile.open(archive_path, 'w') do |zipfile|
54
+ Dir["#{path}/**/**"].reject{ |f| f == archive_path }.each do |file|
55
+ zipfile.add(file.sub(path+'/',''), file)
56
+ end
57
+ end
58
+ archive_path
59
+ end
60
+
61
+ def unzip_file(file, destination)
62
+ Zip::ZipFile.open(file) do |zip_file|
63
+ zip_file.each do |f|
64
+ f_path = File.join(destination, f.name)
65
+ FileUtils.mkdir_p(File.dirname(f_path))
66
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
67
+ end
68
+ end
69
+ end
70
+
71
+ def extract_gamepack
72
+ FileUtils.rmdir path
73
+ unzip_file(tmp_archive, path)
74
+ end
75
+
76
+ def archive_name
77
+ "#{basename}.zip"
78
+ end
79
+
80
+ def path
81
+ Bundler.bundle_path.dup.to_s.sub(%r[/$],'')
82
+ end
83
+
84
+ def basename
85
+ File.basename(path)
86
+ end
87
+
88
+ def archive_path
89
+ File.join(path,basename)+'.zip'
90
+ end
91
+
92
+ def tmp_archive_directory
93
+ "/tmp/"
94
+ end
95
+
96
+ def tmp_archive
97
+ File.join(tmp_archive_directory, archive_name)
98
+ end
99
+ end
100
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler_cacher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bartłomiej Danek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.2.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: rubyzip
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.9
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.9
46
+ - !ruby/object:Gem::Dependency
47
+ name: aws-sdk
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.0
62
+ description: ''
63
+ email:
64
+ - bartek.danek@gmail.com
65
+ executables:
66
+ - bundler_cacher
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - README.md
74
+ - TODO
75
+ - bin/bundler_cacher
76
+ - bundler_cacher.gemspec
77
+ - lib/bundler_cacher.rb
78
+ - lib/bundler_cacher/version.rb
79
+ homepage: https://github.com/bartekd/bundler_cacher
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.8.7
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: 1.3.6
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.24
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: The best way to cache your gems
104
+ test_files: []