spitball 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/spitball-cache-cleanup +22 -0
- data/bin/spitball-server +1 -1
- data/lib/spitball/remote.rb +1 -1
- data/lib/spitball/repo.rb +21 -3
- data/spec/spitball_spec.rb +31 -9
- data/spitball.gemspec +5 -4
- metadata +7 -5
    
        data/Rakefile
    CHANGED
    
    | @@ -21,7 +21,7 @@ begin | |
| 21 21 | 
             
                gem.summary = "get a bundle"
         | 
| 22 22 | 
             
                gem.description = "Use bundler to generate gem tarball packages."
         | 
| 23 23 | 
             
                gem.email = "freels@twitter.com"
         | 
| 24 | 
            -
                gem.homepage = "http:// | 
| 24 | 
            +
                gem.homepage = "http://github.com/freels/spitball"
         | 
| 25 25 | 
             
                gem.authors = ["Matt Freels", "Brandon Mitchell"]
         | 
| 26 26 |  | 
| 27 27 | 
             
                gem.add_dependency 'bundler', '>= 0.9.5'
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.2. | 
| 1 | 
            +
            0.2.2
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spitball'
         | 
| 4 | 
            +
            require 'optparse'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            args = {}
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            opts = OptionParser.new do |opts|
         | 
| 9 | 
            +
              opts.banner = "Usage: spitball-cache-cleanup [options]"
         | 
| 10 | 
            +
              opts.separator ""
         | 
| 11 | 
            +
              opts.separator "options:"
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              opts.on('-w', '--access-window SECONDS', 'Access window within which tarballs are kept. Default 30 days') do |access_window|
         | 
| 14 | 
            +
                args[:access_window] = access_window
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            opts.permute!(ARGV)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            args[:access_window] ||= 2592000
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            Spitball::Repo.clean_up_unused(args[:access_window].to_i)
         | 
    
        data/bin/spitball-server
    CHANGED
    
    | @@ -25,7 +25,7 @@ mime_type :tgz, 'application/x-compressed' | |
| 25 25 | 
             
            # return json array of cached SHAs
         | 
| 26 26 | 
             
            get '/list' do
         | 
| 27 27 | 
             
              content_type :json
         | 
| 28 | 
            -
              JSON.dump Spitball::Repo. | 
| 28 | 
            +
              JSON.dump Spitball::Repo.cached_digests
         | 
| 29 29 | 
             
            end
         | 
| 30 30 |  | 
| 31 31 | 
             
            # return tgz or gemfile of cached SHA or 404
         | 
    
        data/lib/spitball/remote.rb
    CHANGED
    
    
    
        data/lib/spitball/repo.rb
    CHANGED
    
    | @@ -9,14 +9,18 @@ module Spitball::Repo | |
| 9 9 | 
             
              end
         | 
| 10 10 |  | 
| 11 11 | 
             
              def exist?(digest)
         | 
| 12 | 
            -
                File.exist?  | 
| 12 | 
            +
                File.exist? tarball(digest)
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def tarball(digest)
         | 
| 16 | 
            +
                path(digest, 'tgz')
         | 
| 13 17 | 
             
              end
         | 
| 14 18 |  | 
| 15 19 | 
             
              def gemfile(digest)
         | 
| 16 | 
            -
                 | 
| 20 | 
            +
                path(digest, 'gemfile')
         | 
| 17 21 | 
             
              end
         | 
| 18 22 |  | 
| 19 | 
            -
              def  | 
| 23 | 
            +
              def cached_digests
         | 
| 20 24 | 
             
                Dir[File.join(WORKING_DIR, 'bundle_*.tgz')].map do |path|
         | 
| 21 25 | 
             
                  path.match(/bundle_(.*?)\.tgz$/)[1]
         | 
| 22 26 | 
             
                end.compact.uniq.sort
         | 
| @@ -25,4 +29,18 @@ module Spitball::Repo | |
| 25 29 | 
             
              def make_cache_dir
         | 
| 26 30 | 
             
                FileUtils.mkdir_p WORKING_DIR
         | 
| 27 31 | 
             
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def clean_up_unused(access_window)
         | 
| 34 | 
            +
                cutoff_time = Time.now - access_window
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                cached_digests.each do |digest|
         | 
| 37 | 
            +
                  stat = File.stat(tarball(digest))
         | 
| 38 | 
            +
                  access_time = [stat.atime, stat.mtime].max
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  if access_time < cutoff_time
         | 
| 41 | 
            +
                    File.unlink(tarball(digest)) if File.exist? tarball(digest)
         | 
| 42 | 
            +
                    File.unlink(gemfile(digest)) if File.exist? gemfile(digest)
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
              end
         | 
| 28 46 | 
             
            end
         | 
    
        data/spec/spitball_spec.rb
    CHANGED
    
    | @@ -148,27 +148,49 @@ describe Spitball::Repo do | |
| 148 148 | 
             
              end
         | 
| 149 149 |  | 
| 150 150 | 
             
              describe "exist?" do
         | 
| 151 | 
            -
                it "returns true if tarball for a digest  | 
| 151 | 
            +
                it "returns true if tarball for a digest exists" do
         | 
| 152 152 | 
             
                  Spitball::Repo.exist?('digest').should_not == true
         | 
| 153 153 | 
             
                  File.open(Spitball::Repo.path('digest', 'tgz'), 'w') {|f| f.write 'tarball!' }
         | 
| 154 154 | 
             
                  Spitball::Repo.exist?('digest').should == true
         | 
| 155 155 | 
             
                end
         | 
| 156 156 | 
             
              end
         | 
| 157 157 |  | 
| 158 | 
            +
              describe "tarball" do
         | 
| 159 | 
            +
                it "returns the path of the cached tarball for a digest" do
         | 
| 160 | 
            +
                  Spitball::Repo.tarball('digest').should == Spitball::Repo.path('digest', 'tgz')
         | 
| 161 | 
            +
                end
         | 
| 162 | 
            +
              end
         | 
| 163 | 
            +
             | 
| 158 164 | 
             
              describe "gemfile" do
         | 
| 159 | 
            -
                it "returns the  | 
| 160 | 
            -
                  gemfile  | 
| 161 | 
            -
                  File.open(Spitball::Repo.path('digest', 'gemfile'), 'w') {|f| f.write gemfile }
         | 
| 162 | 
            -
                  Spitball::Repo.gemfile('digest').should == gemfile
         | 
| 165 | 
            +
                it "returns the path of the cached gemfile for a digest" do
         | 
| 166 | 
            +
                  Spitball::Repo.gemfile('digest').should == Spitball::Repo.path('digest', 'gemfile')
         | 
| 163 167 | 
             
                end
         | 
| 164 168 | 
             
              end
         | 
| 165 169 |  | 
| 166 | 
            -
              describe " | 
| 170 | 
            +
              describe "cached_digests" do
         | 
| 167 171 | 
             
                it "returns a list of cached bundles" do
         | 
| 168 | 
            -
                  File.open(Spitball::Repo. | 
| 169 | 
            -
                  File.open(Spitball::Repo. | 
| 172 | 
            +
                  File.open(Spitball::Repo.tarball('digest'), 'w') {|f| f.write 'tarball!' }
         | 
| 173 | 
            +
                  File.open(Spitball::Repo.tarball('digest2'), 'w') {|f| f.write 'tarball2!' }
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                  Spitball::Repo.cached_digests.should == ['digest', 'digest2']
         | 
| 176 | 
            +
                end
         | 
| 177 | 
            +
              end
         | 
| 178 | 
            +
             | 
| 179 | 
            +
              describe "clean_up_unused" do
         | 
| 180 | 
            +
                it "removes cached tarballs and gemfiles that haven't been accessed within a certain period" do
         | 
| 181 | 
            +
                  File.open(Spitball::Repo.tarball('digest'), 'w') {|f| f.write 'tarball!' }
         | 
| 182 | 
            +
                  File.open(Spitball::Repo.gemfile('digest'), 'w') {|f| f.write 'gemfile!' }
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                  sleep 2
         | 
| 185 | 
            +
                  File.open(Spitball::Repo.tarball('digest2'), 'w') {|f| f.write 'tarball2!' }
         | 
| 186 | 
            +
                  File.open(Spitball::Repo.gemfile('digest2'), 'w') {|f| f.write 'gemfile2!' }
         | 
| 187 | 
            +
             | 
| 188 | 
            +
                  Spitball::Repo.clean_up_unused(1)
         | 
| 170 189 |  | 
| 171 | 
            -
                  Spitball::Repo. | 
| 190 | 
            +
                  File.exist?(Spitball::Repo.tarball('digest')).should_not == true
         | 
| 191 | 
            +
                  File.exist?(Spitball::Repo.gemfile('digest')).should_not == true
         | 
| 192 | 
            +
                  File.exist?(Spitball::Repo.tarball('digest2')).should == true
         | 
| 193 | 
            +
                  File.exist?(Spitball::Repo.gemfile('digest2')).should == true
         | 
| 172 194 | 
             
                end
         | 
| 173 195 | 
             
              end
         | 
| 174 196 | 
             
            end
         | 
    
        data/spitball.gemspec
    CHANGED
    
    | @@ -5,14 +5,14 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{spitball}
         | 
| 8 | 
            -
              s.version = "0.2. | 
| 8 | 
            +
              s.version = "0.2.2"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Matt Freels", "Brandon Mitchell"]
         | 
| 12 | 
            -
              s.date = %q{2010-08- | 
| 12 | 
            +
              s.date = %q{2010-08-23}
         | 
| 13 13 | 
             
              s.description = %q{Use bundler to generate gem tarball packages.}
         | 
| 14 14 | 
             
              s.email = %q{freels@twitter.com}
         | 
| 15 | 
            -
              s.executables = ["spitball", "spitball-server"]
         | 
| 15 | 
            +
              s.executables = ["spitball", "spitball-cache-cleanup", "spitball-server"]
         | 
| 16 16 | 
             
              s.extra_rdoc_files = [
         | 
| 17 17 | 
             
                "README.md"
         | 
| 18 18 | 
             
              ]
         | 
| @@ -23,6 +23,7 @@ Gem::Specification.new do |s| | |
| 23 23 | 
             
                 "Rakefile",
         | 
| 24 24 | 
             
                 "VERSION",
         | 
| 25 25 | 
             
                 "bin/spitball",
         | 
| 26 | 
            +
                 "bin/spitball-cache-cleanup",
         | 
| 26 27 | 
             
                 "bin/spitball-server",
         | 
| 27 28 | 
             
                 "lib/spitball.rb",
         | 
| 28 29 | 
             
                 "lib/spitball/digest.rb",
         | 
| @@ -34,7 +35,7 @@ Gem::Specification.new do |s| | |
| 34 35 | 
             
                 "spec/spitball_spec.rb",
         | 
| 35 36 | 
             
                 "spitball.gemspec"
         | 
| 36 37 | 
             
              ]
         | 
| 37 | 
            -
              s.homepage = %q{http:// | 
| 38 | 
            +
              s.homepage = %q{http://github.com/freels/spitball}
         | 
| 38 39 | 
             
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 39 40 | 
             
              s.require_paths = ["lib"]
         | 
| 40 41 | 
             
              s.rubygems_version = %q{1.3.7}
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: spitball
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 19
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 2
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.2. | 
| 9 | 
            +
              - 2
         | 
| 10 | 
            +
              version: 0.2.2
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Matt Freels
         | 
| @@ -16,7 +16,7 @@ autorequire: | |
| 16 16 | 
             
            bindir: bin
         | 
| 17 17 | 
             
            cert_chain: []
         | 
| 18 18 |  | 
| 19 | 
            -
            date: 2010-08- | 
| 19 | 
            +
            date: 2010-08-23 00:00:00 -07:00
         | 
| 20 20 | 
             
            default_executable: 
         | 
| 21 21 | 
             
            dependencies: 
         | 
| 22 22 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -82,6 +82,7 @@ description: Use bundler to generate gem tarball packages. | |
| 82 82 | 
             
            email: freels@twitter.com
         | 
| 83 83 | 
             
            executables: 
         | 
| 84 84 | 
             
            - spitball
         | 
| 85 | 
            +
            - spitball-cache-cleanup
         | 
| 85 86 | 
             
            - spitball-server
         | 
| 86 87 | 
             
            extensions: []
         | 
| 87 88 |  | 
| @@ -94,6 +95,7 @@ files: | |
| 94 95 | 
             
            - Rakefile
         | 
| 95 96 | 
             
            - VERSION
         | 
| 96 97 | 
             
            - bin/spitball
         | 
| 98 | 
            +
            - bin/spitball-cache-cleanup
         | 
| 97 99 | 
             
            - bin/spitball-server
         | 
| 98 100 | 
             
            - lib/spitball.rb
         | 
| 99 101 | 
             
            - lib/spitball/digest.rb
         | 
| @@ -105,7 +107,7 @@ files: | |
| 105 107 | 
             
            - spec/spitball_spec.rb
         | 
| 106 108 | 
             
            - spitball.gemspec
         | 
| 107 109 | 
             
            has_rdoc: true
         | 
| 108 | 
            -
            homepage: http:// | 
| 110 | 
            +
            homepage: http://github.com/freels/spitball
         | 
| 109 111 | 
             
            licenses: []
         | 
| 110 112 |  | 
| 111 113 | 
             
            post_install_message: 
         |