compact_index 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: 245906f9f51eec8f2921a83587840d375be27d6d
4
+ data.tar.gz: de264fd5bdc08186916f0b9427f7b3e58d30677c
5
+ SHA512:
6
+ metadata.gz: 4f7fd35bfbcce315c91f8efd93466b2ede5a6c85218c270a4858995d33700209556f7cfa0657b642239089f36652e5dbf9f02f31408637346574d38efd7989b7
7
+ data.tar.gz: d962db2efe1f17c163335d3c578ce3360cd9bce38aa27e86f88b2c410469db317c663cededcbf3e4314271a4c874861f594b9280b6f05017e90178a98095bc67
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ spec/config.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in compact_index.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 fotanus@gmail.com
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,24 @@
1
+ # CompactIndex
2
+
3
+ Backend for bundler compact index. Used by rubygems.org and bundler-api
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'compact_index'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install compact_index
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "compact_index"
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,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,23 @@
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/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "compact_index"
8
+ spec.version = CompactIndex::VERSION
9
+ spec.authors = ["fotanus@gmail.com"]
10
+ spec.email = ["Felipe Tanus"]
11
+
12
+ spec.summary = %q{Backend for compact index}
13
+ spec.homepage = "https://github.com/bundler/compact_index"
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.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,73 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table(:dependencies, :ignore_index_errors=>true) do
4
+ primary_key :id
5
+ String :requirements, :size=>255
6
+ DateTime :created_at
7
+ DateTime :updated_at
8
+ Integer :rubygem_id
9
+ Integer :version_id
10
+ String :scope, :size=>255
11
+ String :unresolved_name, :size=>255
12
+
13
+ index [:rubygem_id], :name=>:index_dependencies_on_rubygem_id
14
+ index [:unresolved_name], :name=>:index_dependencies_on_unresolved_name
15
+ index [:version_id], :name=>:index_dependencies_on_version_id
16
+ end
17
+
18
+ create_table(:linksets, :ignore_index_errors=>true) do
19
+ primary_key :id
20
+ Integer :rubygem_id
21
+ String :home, :size=>255
22
+ String :wiki, :size=>255
23
+ String :docs, :size=>255
24
+ String :mail, :size=>255
25
+ String :code, :size=>255
26
+ String :bugs, :size=>255
27
+ DateTime :created_at
28
+ DateTime :updated_at
29
+
30
+ index [:rubygem_id], :name=>:index_linksets_on_rubygem_id
31
+ end
32
+
33
+ create_table(:rubygems, :ignore_index_errors=>true) do
34
+ primary_key :id
35
+ String :name, :size=>255
36
+ DateTime :created_at
37
+ DateTime :updated_at
38
+ Integer :downloads, :default=>0
39
+ String :slug, :size=>255
40
+
41
+ index [:name], :name=>:index_rubygems_on_name, :unique=>true
42
+ end
43
+
44
+ create_table(:versions, :ignore_index_errors=>true) do
45
+ primary_key :id
46
+ String :authors, :text=>true
47
+ String :description, :text=>true
48
+ String :number, :size=>255
49
+ Integer :rubygem_id
50
+ DateTime :built_at
51
+ DateTime :updated_at
52
+ String :rubyforge_project, :size=>255
53
+ String :summary, :text=>true
54
+ String :platform, :size=>255
55
+ DateTime :created_at
56
+ TrueClass :indexed, :default=>true
57
+ TrueClass :prerelease
58
+ Integer :position
59
+ TrueClass :latest
60
+ String :full_name, :size=>255
61
+
62
+ index [:built_at], :name=>:index_versions_on_built_at
63
+ index [:created_at], :name=>:index_versions_on_created_at
64
+ index [:full_name], :name=>:index_versions_on_full_name
65
+ index [:indexed], :name=>:index_versions_on_indexed
66
+ index [:number], :name=>:index_versions_on_number
67
+ index [:position], :name=>:index_versions_on_position
68
+ index [:prerelease], :name=>:index_versions_on_prerelease
69
+ index [:rubygem_id], :name=>:index_versions_on_rubygem_id
70
+ index [:rubygem_id, :number, :platform], :name=>:index_versions_on_rubygem_id_and_number_and_platform, :unique=>true
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,74 @@
1
+ Sequel.migration do
2
+ up do
3
+ drop_table :linksets
4
+
5
+ alter_table :dependencies do
6
+ drop_column :created_at
7
+ drop_column :updated_at
8
+ drop_column :unresolved_name
9
+ end
10
+
11
+ alter_table :rubygems do
12
+ drop_column :created_at
13
+ drop_column :updated_at
14
+ drop_column :downloads
15
+ drop_column :slug
16
+ end
17
+
18
+ alter_table :versions do
19
+ drop_column :created_at
20
+ drop_column :updated_at
21
+ drop_column :authors
22
+ drop_column :description
23
+ drop_column :built_at
24
+ drop_column :rubyforge_project
25
+ drop_column :position
26
+ drop_column :latest
27
+ end
28
+ end
29
+
30
+ down do
31
+ create_table(:linksets, :ignore_index_errors=>true) do
32
+ primary_key :id
33
+ Integer :rubygem_id
34
+ String :home, :size=>255
35
+ String :wiki, :size=>255
36
+ String :docs, :size=>255
37
+ String :mail, :size=>255
38
+ String :code, :size=>255
39
+ String :bugs, :size=>255
40
+ DateTime :created_at
41
+ DateTime :updated_at
42
+
43
+ index [:rubygem_id], :name=>:index_linksets_on_rubygem_id
44
+ end
45
+
46
+ alter_table :dependencies do
47
+ add_column :created_at, DateTime
48
+ add_column :updated_at, DateTime
49
+ add_column :unresolved_name, String, :size=>255
50
+ add_index [:unresolved_name], :name=>:index_dependencies_on_unresolved_name
51
+ end
52
+
53
+ alter_table :rubygems do
54
+ add_column :created_at, DateTime
55
+ add_column :updated_at, DateTime
56
+ add_column :downloads, Integer, :default=>0
57
+ add_column :slug, String, :size=>255
58
+ end
59
+
60
+ alter_table :versions do
61
+ add_column :created_at, DateTime
62
+ add_column :updated_at, DateTime
63
+ add_column :authors, String, :text=>true
64
+ add_column :description, String, :text=>true
65
+ add_column :built_at, DateTime
66
+ add_column :rubyforge_project, String, :size=>255
67
+ add_column :position, Integer
68
+ add_column :latest, TrueClass
69
+ add_index [:created_at], :name=>:index_versions_on_created_at
70
+ add_index [:built_at], :name=>:index_versions_on_built_at
71
+ add_index [:position], :name=>:index_versions_on_position
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ Sequel.migration do
2
+ up do
3
+ alter_table :versions do
4
+ add_column :rubygems_version, String, :size=>255
5
+ add_column :required_ruby_version, String, :size=>255
6
+ end
7
+ end
8
+
9
+ down do
10
+ alter_table :versions do
11
+ drop_column :rubygems_version
12
+ drop_column :required_ruby_version
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table :rubygems do
4
+ add_column :deps_md5, String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table :checksums do
4
+ primary_key :id
5
+ String :name
6
+ String :md5
7
+
8
+ index [:name], name: :index_checksums_on_name, unqiue: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table :versions do
4
+ add_column :created_at, DateTime
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table :versions do
4
+ add_column :checksum, String, :size => 255
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require "compact_index/version"
2
+
3
+ module CompactIndex
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,91 @@
1
+ require 'compact_index'
2
+
3
+ # Return data about all the gems: all gem names, all versions of all gems, all dependencies for all versions of a gem
4
+ class CompactIndex::GemInfo
5
+ DepKey = Struct.new(:name, :number, :platform, :required_ruby_version, :rubygems_version, :checksum)
6
+
7
+ def initialize(connection)
8
+ @conn = connection
9
+ end
10
+
11
+ # @param [String] array of strings with the gem names
12
+ def deps_for(gems = [])
13
+ dataset =
14
+ if gems.any?
15
+ @conn[<<-SQL, Sequel.value_list(gems)]
16
+ SELECT rv.name, rv.number, rv.platform, rv.required_ruby_version, rv.checksum,
17
+ rv.rubygems_version, d.requirements, for_dep_name.name dep_name
18
+ FROM
19
+ (SELECT r.name, v.number, v.platform,v.rubygems_version, v.checksum,
20
+ v.required_ruby_version, v.id AS version_id
21
+ FROM rubygems AS r, versions AS v
22
+ WHERE v.rubygem_id = r.id
23
+ AND v.indexed is true
24
+ AND r.name IN ?) AS rv
25
+ LEFT JOIN dependencies AS d ON
26
+ d.version_id = rv.version_id
27
+ LEFT JOIN rubygems AS for_dep_name ON
28
+ d.rubygem_id = for_dep_name.id
29
+ AND d.scope = 'runtime';
30
+ SQL
31
+ else
32
+ @conn[<<-SQL]
33
+ SELECT rv.name, rv.number, rv.platform, d.requirements, for_dep_name.name dep_name
34
+ FROM
35
+ (SELECT r.name, v.number, v.platform, v.id AS version_id
36
+ FROM rubygems AS r, versions AS v
37
+ WHERE v.rubygem_id = r.id
38
+ AND v.indexed is true) AS rv
39
+ LEFT JOIN dependencies AS d ON
40
+ d.version_id = rv.version_id
41
+ LEFT JOIN rubygems AS for_dep_name ON
42
+ d.rubygem_id = for_dep_name.id
43
+ AND d.scope = 'runtime';
44
+ SQL
45
+ end
46
+
47
+ deps = {}
48
+
49
+ dataset.each do |row|
50
+ key = DepKey.new(row[:name], row[:number], row[:platform], row[:required_ruby_version], row[:rubygems_version], row[:checksum])
51
+ deps[key] = [] unless deps[key]
52
+ deps[key] << [row[:dep_name], row[:requirements]] if row[:dep_name]
53
+ end
54
+
55
+ deps.map do |dep_key, gem_deps|
56
+ {
57
+ name: dep_key.name,
58
+ number: dep_key.number,
59
+ platform: dep_key.platform,
60
+ rubygems_version: dep_key.rubygems_version,
61
+ required_ruby_version: dep_key.required_ruby_version,
62
+ checksum: dep_key.checksum,
63
+ dependencies: gem_deps
64
+ }
65
+ end
66
+ end
67
+
68
+ # return list of gem names
69
+ def names
70
+ @conn[:rubygems].select(:name).order(:name).all.map {|r| r[:name] }
71
+ end
72
+
73
+ # return a list of gem names and their versions
74
+ def versions
75
+ specs_hash = Hash.new {|h, k| h[k] = [] }
76
+ rows = @conn[<<-SQL]
77
+ SELECT v.full_name, v.number, v.platform
78
+ FROM versions AS v
79
+ WHERE v.indexed is true
80
+ SQL
81
+ rows.each do |row|
82
+ full_name = row[:full_name]
83
+ version = row[:number]
84
+ version += "-" << row[:platform] unless row[:platform] == "ruby"
85
+ name = full_name.chomp("-" << version)
86
+ specs_hash[name] << version
87
+ end
88
+
89
+ specs_hash.each {|k, v| v.sort! }
90
+ end
91
+ end
@@ -0,0 +1,3 @@
1
+ module CompactIndex
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,76 @@
1
+ require 'compact_index'
2
+
3
+ class CompactIndex::VersionsFile
4
+ PATH = "versions.list"
5
+ def initialize(connection)
6
+ @conn = connection
7
+ end
8
+
9
+ def create_or_update
10
+ if File.exists? PATH
11
+ update
12
+ else
13
+ create
14
+ end
15
+ end
16
+
17
+ def create
18
+ content = Time.now.to_i.to_s
19
+ content += "\n---\n"
20
+ content += gems_for_new_file
21
+
22
+ File.open(PATH, 'w') do |io|
23
+ io.write content
24
+ end
25
+ end
26
+
27
+ def update
28
+ to_write = with_new_gems
29
+ File.open(PATH, 'w') do |io|
30
+ io.write to_write
31
+ end
32
+ end
33
+
34
+ def with_new_gems
35
+ if new_gems.empty?
36
+ content
37
+ else
38
+ content + "\n" + new_gems
39
+ end
40
+ end
41
+
42
+ private
43
+ def content
44
+ File.open(PATH).read
45
+
46
+ end
47
+
48
+ def created_at
49
+ DateTime.parse(File.mtime(PATH).to_s)
50
+ end
51
+
52
+ def gems_for_new_file
53
+ dataset = @conn[<<-SQL]
54
+ SELECT
55
+ r.name, string_agg(
56
+ concat_ws('-', v.number, nullif(v.platform,'ruby')), ','
57
+ ORDER BY number ASC
58
+ )
59
+ FROM rubygems AS r, versions AS v
60
+ WHERE v.rubygem_id = r.id AND
61
+ v.indexed is true
62
+ GROUP BY r.name
63
+ SQL
64
+ dataset.map { |entry| "#{entry[:name]} #{entry[:string_agg]}" }.join("\n")
65
+ end
66
+
67
+ def new_gems
68
+ dataset = @conn[<<-SQL, created_at]
69
+ SELECT r.name, concat_ws('-', v.number, nullif(v.platform,'ruby'))
70
+ FROM rubygems AS r, versions AS v
71
+ WHERE v.rubygem_id = r.id AND v.indexed is true AND v.created_at > ?
72
+ ORDER BY v.created_at, r.name, concat_ws
73
+ SQL
74
+ dataset.map { |entry| "#{entry[:name]} #{entry[:concat_ws]}" }.join("\n")
75
+ end
76
+ end
@@ -0,0 +1,4 @@
1
+ 1433423251
2
+ ---
3
+ a 0.0.1
4
+ b 0.0.2,0.1.1-java,0.1.2
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compact_index
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fotanus@gmail.com
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-21 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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
+ description:
42
+ email:
43
+ - Felipe Tanus
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - compact_index.gemspec
59
+ - db/migrations/01_rubygems_org_schema_dump.rb
60
+ - db/migrations/02_prune.rb
61
+ - db/migrations/03_add_ruby_and_rubygems_requirements.rb
62
+ - db/migrations/04_add_deps_md5_to_rubygems.rb
63
+ - db/migrations/05_create_checksums.rb
64
+ - db/migrations/06_add_created_at_to_versions.rb
65
+ - db/migrations/07_add_checksum_to_versions.rb
66
+ - lib/compact_index.rb
67
+ - lib/compact_index/gem_info.rb
68
+ - lib/compact_index/version.rb
69
+ - lib/compact_index/versions_file.rb
70
+ - versions.list
71
+ homepage: https://github.com/bundler/compact_index
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Backend for compact index
95
+ test_files: []