compact_index_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18f334a60412f00251629bf03ce547871b37a714
4
+ data.tar.gz: 22e80a4875200879d9ee784f3ec9a392930a894a
5
+ SHA512:
6
+ metadata.gz: 633282b34accd47e64833d523a4c9d226020eed42b36b1a4fcf79b00f36404b3a2b84d39c86ad4570a3c2ba6bc00accb30e962e4d0ac5dca2de5a8e22e70d1e0
7
+ data.tar.gz: be2f1c89aeffffc872bce26d168f24c1e023530c58dd9c0155f6cb8c1860b09401608e0524a9c99fb0a5682e419bf60069dc16bdbfb3f0555d57639ebdc9b7e4
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,99 @@
1
+ inherit_from:
2
+ - .rubocop_todo.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - tmp/**/*
7
+ - vendor/**/*
8
+ - bin/**/*
9
+ DisplayCopNames: true
10
+
11
+ # Lint
12
+
13
+ # They are idiomatic
14
+ Lint/AssignmentInCondition:
15
+ Enabled: false
16
+
17
+ Lint/EndAlignment:
18
+ AlignWith: variable
19
+
20
+ # Style
21
+
22
+ Style/AccessModifierIndentation:
23
+ EnforcedStyle: outdent
24
+
25
+ Style/AlignParameters:
26
+ EnforcedStyle: with_fixed_indentation
27
+
28
+ Style/MultilineOperationIndentation:
29
+ EnforcedStyle: indented
30
+
31
+ Style/SpaceInsideBlockBraces:
32
+ SpaceBeforeBlockParameters: false
33
+
34
+ Style/TrivialAccessors:
35
+ Enabled: false
36
+
37
+ # We adopted raise instead of fail.
38
+ Style/SignalException:
39
+ EnforcedStyle: only_raise
40
+
41
+ Style/StringLiterals:
42
+ EnforcedStyle: double_quotes
43
+
44
+ Style/StringLiteralsInInterpolation:
45
+ EnforcedStyle: double_quotes
46
+
47
+ # Having these make it easier to *not* forget to add one when adding a new
48
+ # value and you can simply copy the previous line.
49
+ Style/TrailingComma:
50
+ EnforcedStyleForMultiline: comma
51
+
52
+ # 1.8.7 support
53
+
54
+ Style/HashSyntax:
55
+ EnforcedStyle: hash_rockets
56
+
57
+ Style/Lambda:
58
+ Enabled: false
59
+
60
+ Style/DotPosition:
61
+ EnforcedStyle: trailing
62
+
63
+ Style/EachWithObject:
64
+ Enabled: false
65
+
66
+ Style/SpecialGlobalVars:
67
+ Enabled: false
68
+
69
+ Style/TrailingComma:
70
+ Enabled: false
71
+
72
+ Performance/FlatMap:
73
+ Enabled: false
74
+
75
+ # Metrics
76
+
77
+ # Arbitrary max lengths for classes simply do not work and enabling this will
78
+ # lead to a never ending stream of annoyance and changes.
79
+ Metrics/ClassLength:
80
+ Enabled: false
81
+
82
+ # Arbitrary max lengths for methods simply do not work and enabling this will
83
+ # lead to a never ending stream of annoyance and changes.
84
+ Metrics/MethodLength:
85
+ Enabled: false
86
+
87
+ # No enforced convention here.
88
+ Metrics/BlockNesting:
89
+ Enabled: false
90
+
91
+ # It will be obvious which code is complex, Rubocop should only lint simple
92
+ # rules for us.
93
+ Metrics/AbcSize:
94
+ Enabled: false
95
+
96
+ # It will be obvious which code is complex, Rubocop should only lint simple
97
+ # rules for us.
98
+ Metrics/CyclomaticComplexity:
99
+ Enabled: false
@@ -0,0 +1,20 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-08-19 00:08:04 -0600 using RuboCop version 0.33.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 7
10
+ # Configuration parameters: AllowURI, URISchemes.
11
+ Metrics/LineLength:
12
+ Max: 104
13
+
14
+ # Offense count: 4
15
+ Style/Documentation:
16
+ Exclude:
17
+ - 'lib/compact_index_client.rb'
18
+ - 'lib/compact_index_client/cache.rb'
19
+ - 'lib/compact_index_client/updater.rb'
20
+ - 'lib/compact_index_client/version.rb'
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.7
7
+ - 2.2.3
8
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 (2015-08-22)
2
+
3
+ - Initial port of Bundler functionality.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rspec", "~> 3.0"
7
+ gem "rubocop", "0.33.0", :install_if => (RUBY_VERSION >= "2.0")
8
+ end
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ compact_index_client (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.1.0)
10
+ astrolabe (1.3.1)
11
+ parser (~> 2.2)
12
+ diff-lcs (1.2.5)
13
+ parser (2.2.2.6)
14
+ ast (>= 1.1, < 3.0)
15
+ powerpack (0.1.1)
16
+ rainbow (2.0.0)
17
+ rake (10.4.2)
18
+ rspec (3.3.0)
19
+ rspec-core (~> 3.3.0)
20
+ rspec-expectations (~> 3.3.0)
21
+ rspec-mocks (~> 3.3.0)
22
+ rspec-core (3.3.2)
23
+ rspec-support (~> 3.3.0)
24
+ rspec-expectations (3.3.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.3.0)
27
+ rspec-mocks (3.3.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.3.0)
30
+ rspec-support (3.3.0)
31
+ rubocop (0.33.0)
32
+ astrolabe (~> 1.3)
33
+ parser (>= 2.2.2.5, < 3.0)
34
+ powerpack (~> 0.1)
35
+ rainbow (>= 1.99.1, < 3.0)
36
+ ruby-progressbar (~> 1.4)
37
+ ruby-progressbar (1.7.5)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (~> 1.10)
44
+ compact_index_client!
45
+ rake (~> 10.0)
46
+ rspec (~> 3.0)
47
+ rubocop (= 0.33.0)
48
+
49
+ BUNDLED WITH
50
+ 1.10.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Samuel E. Giddins
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.
@@ -0,0 +1,36 @@
1
+ # CompactIndexClient
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'compact_index_client'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install compact_index_client
18
+
19
+ ## Usage
20
+
21
+ Initialize a new `CompactIndexClient` with a root directory for the local copy of the compact index, and a block used to make HTTP requests.
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bundler/compact_index_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ begin
7
+ require "rubocop/rake_task"
8
+ RuboCop::RakeTask.new
9
+ task :spec => :rubocop
10
+ rescue LoadError
11
+ nil
12
+ end
13
+
14
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "compact_index_client"
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
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rubocop', 'rubocop')
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "compact_index_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "compact_index_client"
8
+ spec.version = CompactIndexClient::VERSION
9
+ spec.authors = ["Samuel E. Giddins"]
10
+ spec.email = ["segiddins@segiddins.me"]
11
+
12
+ spec.summary = "The client for the new Bundler compact index format."
13
+ spec.homepage = "https://github.com/bundler/compact_index_client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,57 @@
1
+ require "pathname"
2
+ require "set"
3
+
4
+ class CompactIndexClient
5
+ require "compact_index_client/cache"
6
+ require "compact_index_client/updater"
7
+ require "compact_index_client/version"
8
+
9
+ def initialize(directory, fetcher)
10
+ @directory = Pathname.new(directory)
11
+ @updater = Updater.new(fetcher)
12
+ @cache = Cache.new(@directory)
13
+ @endpoints = Set.new
14
+ @info_checksums_by_name = {}
15
+ end
16
+
17
+ def names
18
+ update(@cache.names_path, "names")
19
+ @cache.names
20
+ end
21
+
22
+ def versions
23
+ update(@cache.versions_path, "versions")
24
+ versions, @info_checksums_by_name = @cache.versions
25
+ versions
26
+ end
27
+
28
+ def dependencies(names)
29
+ names.each {|n| update_info(n) }
30
+ names.map do |name|
31
+ @cache.dependencies(name).map {|d| d.unshift(name) }
32
+ end.flatten(1)
33
+ end
34
+
35
+ def spec(name, version, platform = nil)
36
+ update_info(name)
37
+ @cache.specific_dependency(name, version, platform)
38
+ end
39
+
40
+ private
41
+
42
+ def update(local_path, remote_path)
43
+ return if @endpoints.include?(remote_path)
44
+ @updater.update(local_path, url(remote_path))
45
+ @endpoints << remote_path
46
+ end
47
+
48
+ def update_info(name)
49
+ path = @cache.dependencies_path(name)
50
+ return if @info_checksums_by_name[name] == @updater.checksum_for_file(path)
51
+ update(path, "info/#{name}")
52
+ end
53
+
54
+ def url(path)
55
+ path
56
+ end
57
+ end
@@ -0,0 +1,80 @@
1
+ class CompactIndexClient
2
+ class Cache
3
+ attr_reader :directory
4
+
5
+ def initialize(directory)
6
+ @directory = Pathname.new(directory).expand_path
7
+ FileUtils.mkdir_p dependencies_path(nil)
8
+ end
9
+
10
+ def names
11
+ lines(names_path)
12
+ end
13
+
14
+ def names_path
15
+ directory + "names"
16
+ end
17
+
18
+ def versions
19
+ versions_by_name = Hash.new {|hash, key| hash[key] = [] }
20
+ info_checksums_by_name = {}
21
+ lines(versions_path).map do |line|
22
+ next if line == "-1"
23
+ name, versions_string, info_checksum = line.split(" ", 3)
24
+ info_checksums_by_name[name] = info_checksum || ""
25
+ versions_by_name[name].concat(versions_string.split(",").map! do |version|
26
+ version.split("-", 2).unshift(name)
27
+ end)
28
+ end
29
+ [versions_by_name, info_checksums_by_name]
30
+ end
31
+
32
+ def versions_path
33
+ directory + "versions"
34
+ end
35
+
36
+ def dependencies(name)
37
+ lines(dependencies_path(name)).map do |line|
38
+ parse_gem(line)
39
+ end
40
+ end
41
+
42
+ def dependencies_path(name)
43
+ directory + "dependencies" + name.to_s
44
+ end
45
+
46
+ def specific_dependency(name, version, platform)
47
+ pattern = [version, platform].compact.join("-")
48
+ matcher = /\A#{Regexp.escape(pattern)}\b/ unless pattern.empty?
49
+ lines(dependencies_path(name)).each do |line|
50
+ return parse_gem(line) if line =~ matcher
51
+ end if matcher
52
+ nil
53
+ end
54
+
55
+ private
56
+
57
+ def lines(path)
58
+ return [] unless path.file?
59
+ lines = path.read.lines
60
+ header = lines.index("---\n")
61
+ lines = header ? lines[header + 1..-1] : lines
62
+ lines.each!(&:strip!)
63
+ end
64
+
65
+ def parse_gem(string)
66
+ version_and_platform, rest = string.split(" ", 2)
67
+ version, platform = version_and_platform.split("-", 2)
68
+ dependencies, requirements = rest.split("|", 2).map {|s| s.split(",") } if rest
69
+ dependencies = dependencies ? dependencies.map {|d| parse_dependency(d) } : []
70
+ requirements = requirements ? requirements.map {|r| parse_dependency(r) } : []
71
+ [version, platform, dependencies, requirements]
72
+ end
73
+
74
+ def parse_dependency(string)
75
+ dependency = string.split(":")
76
+ dependency[-1] = dependency[-1].split("&")
77
+ dependency
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,29 @@
1
+ class CompactIndexClient
2
+ class Updater
3
+ attr_reader :fetcher
4
+ def initialize(fetcher)
5
+ @fetcher = fetcher
6
+ end
7
+
8
+ def update(local_path, remote_path)
9
+ headers = {}
10
+ if local_path.file?
11
+ headers["If-None-Match"] = checksum_for_file(local_path)
12
+ headers["Range"] = "bytes=#{local_path.size}-"
13
+ end
14
+ response = fetcher.call(remote_path, headers)
15
+ return if response.is_a?(Net::HTTPNotModified)
16
+ mode = response.is_a?(Net::HTTPPartialContent) ? "a" : "w"
17
+ local_path.open(mode) {|f| f << response.body }
18
+
19
+ return if checksum_for_file(local_path) == response["ETag"]
20
+ local_path.delete
21
+ update(local_path, remote_path)
22
+ end
23
+
24
+ def checksum_for_file(path)
25
+ return nil unless path.file?
26
+ Digest::MD5.file(path).hexdigest
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ class CompactIndexClient
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compact_index_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel E. Giddins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-23 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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
+ description:
56
+ email:
57
+ - segiddins@segiddins.me
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".rubocop_todo.yml"
66
+ - ".travis.yml"
67
+ - CHANGELOG.md
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/rake
75
+ - bin/rspec
76
+ - bin/rubocop
77
+ - bin/setup
78
+ - compact_index_client.gemspec
79
+ - lib/compact_index_client.rb
80
+ - lib/compact_index_client/cache.rb
81
+ - lib/compact_index_client/updater.rb
82
+ - lib/compact_index_client/version.rb
83
+ homepage: https://github.com/bundler/compact_index_client
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: The client for the new Bundler compact index format.
107
+ test_files: []