rbs-src 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
+ SHA256:
3
+ metadata.gz: 49a3f8cd78e54658b9eb73372f426f9b349153199145620d371a0820e2dcfee2
4
+ data.tar.gz: 21a2d80857939a03e9f3e1de3f0e789d8532d52060e809715ebdf8dc8e890dfb
5
+ SHA512:
6
+ metadata.gz: c180657f37217b65bcadce2744d8b3a272382cbf03a8226cd319d409fd546040d11b288ba11d6d4c555598506aad0a0f732b9240b449fd9dcc36729f3aa1e0f5
7
+ data.tar.gz: bb162c3e2dacc635c6116ced85e16608429ef2fb2dac8106a09e248aa99346e24578b4c453498ba61852c5f0fa21e180380550881cf83551ca1e5fbb1f1fbce8
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders 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, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at matsumoto@soutaro.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rbs-src.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "steep", require: false
13
+ gem "rbs"
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rbs-src (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (7.0.6)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ ast (2.4.2)
15
+ concurrent-ruby (1.2.2)
16
+ csv (3.2.7)
17
+ ffi (1.15.5)
18
+ fileutils (1.7.1)
19
+ i18n (1.14.1)
20
+ concurrent-ruby (~> 1.0)
21
+ json (2.6.3)
22
+ language_server-protocol (3.17.0.3)
23
+ listen (3.8.0)
24
+ rb-fsevent (~> 0.10, >= 0.10.3)
25
+ rb-inotify (~> 0.9, >= 0.9.10)
26
+ logger (1.5.3)
27
+ minitest (5.19.0)
28
+ parser (3.2.2.3)
29
+ ast (~> 2.4.1)
30
+ racc
31
+ racc (1.7.1)
32
+ rainbow (3.1.1)
33
+ rake (13.0.6)
34
+ rb-fsevent (0.11.2)
35
+ rb-inotify (0.10.1)
36
+ ffi (~> 1.0)
37
+ rbs (3.1.2)
38
+ securerandom (0.2.2)
39
+ steep (1.5.2)
40
+ activesupport (>= 5.1)
41
+ concurrent-ruby (>= 1.1.10)
42
+ csv (>= 3.0.9)
43
+ fileutils (>= 1.1.0)
44
+ json (>= 2.1.0)
45
+ language_server-protocol (>= 3.15, < 4.0)
46
+ listen (~> 3.0)
47
+ logger (>= 1.3.0)
48
+ parser (>= 3.1)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ rbs (>= 3.1.0)
51
+ securerandom (>= 0.1)
52
+ strscan (>= 1.0.0)
53
+ terminal-table (>= 2, < 4)
54
+ strscan (3.0.6)
55
+ terminal-table (3.0.2)
56
+ unicode-display_width (>= 1.1.1, < 3)
57
+ tzinfo (2.0.6)
58
+ concurrent-ruby (~> 1.0)
59
+ unicode-display_width (2.4.2)
60
+
61
+ PLATFORMS
62
+ arm64-darwin-22
63
+
64
+ DEPENDENCIES
65
+ minitest (~> 5.0)
66
+ rake (~> 13.0)
67
+ rbs
68
+ rbs-src!
69
+ steep
70
+
71
+ BUNDLED WITH
72
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Soutaro Matsumoto
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.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # rbs-src
2
+
3
+ rbs-src helps editing RBS files with `rbs collection`.
4
+
5
+ ## The workflow
6
+
7
+ rbs-src helps editing RBS files by having git repositories for each gems and making symlinks to the repositories.
8
+
9
+ Assume you have a rbs collection setup loading activesupport-7.0 and sidekiq-6.2.
10
+ Running the `rbs-src setup` will make repositories and symlinks as the following:
11
+
12
+ ```
13
+ - (Repository root)
14
+ - Gemfile and other files
15
+ - rbs_collection.yaml
16
+ - rbs_collection.lock.yaml
17
+ - tmp/rbs-src
18
+ - activesupport-7.0 (a working copy of https://github.com/ruby/rbs_gem_collection.git)
19
+ - gems/activesupport/7.0/*.rbs (RBS files for activesupport-7.0)
20
+ - sidekiq-6.0 (another working copy of https://github.com/ruby/rbs_gem_collection.git)
21
+ - gems/sidekiq/6.2/*.rbs (RBS files for sidekiq-6.2)
22
+ - sig/
23
+ - **/*.rbs (RBS files for your Ruby program)
24
+ - rbs-src/activesupport-7.0 (Symlink to /tmp/rbs-src/activesupport-7.0/gems/activesupport/7.0)
25
+ - rbs-src/sidekiq-6.2 (Symlink to /tmp/rbs-src/sidekiq-6.2/gems/sidekiq/6.2)
26
+ ```
27
+
28
+ The project structure allows the following workflow:
29
+
30
+ 1. You can edit the RBS files of rbs collection directly through `sig/rbs-src/*/**.rbs`
31
+ 2. Your changes are detected by Steep and used to type check your Ruby program code
32
+ 3. You can push your changes to upstream through the git repositories under `tmp/rbs-src`
33
+
34
+ ## Installation
35
+
36
+ $ gem install rbs-src
37
+
38
+ ## Usage
39
+
40
+ ### rbs-src setup
41
+
42
+ Load gem dependencies from `rbs_collection.lock.yaml` and set up all repositories and symlinks.
43
+
44
+ $ rbs-src setup
45
+
46
+ #### For Steep users
47
+
48
+ You need to edit your Steepfile to let the type checker stop using rbs-collection.
49
+
50
+ ```ruby
51
+ # Steepfile
52
+
53
+ target ... do
54
+ # Existing config...
55
+
56
+ # Add `#signature` call to support loading RBS files from symlinked directory
57
+ signature "sig/rbs-src/*/**/*.rbs"
58
+
59
+ # Stop loading libraries through rbs-collection
60
+ disable_collection()
61
+
62
+ # Load standard libraries and gems manually
63
+ library('abbrev')
64
+ library('date')
65
+ # ...
66
+ end
67
+ ```
68
+
69
+ ### rbs-src link
70
+
71
+ The command clones and set up a symlink of a ruby gem, not loaded from `rbs_collection.lock.yaml`.
72
+
73
+ $ rbs-src link https://github.com/ruby/gem_rbs_collection.git active_emoji 0.0
74
+
75
+ This is typically useful for adding new gem to one of the collections.
76
+ The command will clone the git repository for `active_emoji-0.0` and make a symlink to non-existing directory.
77
+ You can add directories in the repository for `active_emoji-0.0` and start writing RBS files through the symlink.
78
+ Once you finished the edit, you can push the RBS files to upstream!
79
+
80
+ ## Development
81
+
82
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
+
84
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/soutaro/rbs-src. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/soutaro/rbs-src/blob/main/CODE_OF_CONDUCT.md).
89
+
90
+ ## License
91
+
92
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
93
+
94
+ ## Code of Conduct
95
+
96
+ Everyone interacting in the Rbs::Src project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/soutaro/rbs-src/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
data/Steepfile ADDED
@@ -0,0 +1,38 @@
1
+ D = Steep::Diagnostic
2
+
3
+ target :lib do
4
+ signature "sig"
5
+ signature "sig/rbs-src/*/**/*.rbs"
6
+
7
+ check "lib" # Directory name
8
+
9
+
10
+ configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
11
+ # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
12
+ # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
13
+ # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
14
+ # configure_code_diagnostics do |hash| # You can setup everything yourself
15
+ # hash[D::Ruby::NoMethod] = :information
16
+ # end
17
+
18
+ library('abbrev')
19
+ library('date')
20
+ library('dbm')
21
+ library('json')
22
+ library('logger')
23
+ library('minitest')
24
+ library('monitor')
25
+ library('mutex_m')
26
+ library('optparse')
27
+ library('pathname')
28
+ library('pstore')
29
+ library('rbs:3.1.2')
30
+ library('rdoc')
31
+ library('securerandom')
32
+ library('singleton')
33
+ library('time')
34
+ library('tsort')
35
+ library('yaml')
36
+
37
+ disable_collection
38
+ end
data/exe/rbs-src ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.join(__dir__, "../lib")
4
+
5
+ require "rbs/src"
6
+ require "rbs/src/cli"
7
+
8
+ exit Rbs::Src::CLI.start(ARGV)
@@ -0,0 +1,175 @@
1
+ require "optparse"
2
+
3
+ module Rbs
4
+ module Src
5
+ class CLI
6
+ def self.start(argv)
7
+ command = argv.shift
8
+
9
+ case command
10
+ when "link"
11
+ repository_prefix = Pathname("tmp/rbs-src")
12
+ rbs_prefix = Pathname("sig/rbs-src")
13
+ repository_dir = Pathname("gems")
14
+
15
+ OptionParser.new do |opts|
16
+ opts.on("--repo-prefix=PREFIX", "The location to put repository in (default: #{repository_prefix})") { repository_prefix = Pathname(_1) }
17
+ opts.on("--repo-dir=DIR", "The collection repository dir name (default: #{repository_dir})") { repository_dir = Pathname(_1) }
18
+ opts.on("--rbs-prefix=PREFIX", "The location to put symlinks in (default: #{rbs_prefix})") { rbs_prefix = Pathname(_1) }
19
+
20
+ opts.banner = <<~BANNER
21
+ Usage: rbs-src link [options] repo_url gem_name gem_version
22
+
23
+ Clone the repository and set up a symlink.
24
+
25
+ Example:
26
+ $ rbs-src link https://github.com/ruby/gem_rbs_collection.git activerecord 7.0
27
+ $ rbs-src link https://github.com/ruby/gem_rbs_collection.git parseg 1.0
28
+
29
+ Options:
30
+ BANNER
31
+ end.parse!(argv)
32
+
33
+ repository_prefix.mkpath
34
+ rbs_prefix.mkpath
35
+
36
+ repo_url = argv.shift or raise
37
+ gem_name = argv.shift or raise
38
+ gem_version = argv.shift or raise
39
+
40
+ gem = Gem.new(
41
+ name: gem_name,
42
+ version: gem_version,
43
+ repository_prefix: repository_prefix,
44
+ repository_dir: repository_dir,
45
+ rbs_prefix: rbs_prefix
46
+ )
47
+
48
+ runner = CommandRunner.new(stdout: STDOUT)
49
+
50
+ runner.push "Setting up #{gem.name}-#{gem.version}" do
51
+ runner.push "Cloning git repository into #{gem.repository_root}" do
52
+ if gem.repository_root.directory?
53
+ runner.puts "Skipping already exist"
54
+ else
55
+ gem.clone(runner, repository_url: repo_url, commit: nil)
56
+ end
57
+ end
58
+
59
+ runner.push "Linking to #{gem.rbs_path}" do
60
+ unless gem.repository_path.exist?
61
+ runner.puts "File.symlink..."
62
+ gem.link()
63
+ else
64
+ runner.puts "Skipping already exist"
65
+ end
66
+ end
67
+ end
68
+
69
+ 0
70
+ when "setup"
71
+ rbs_collection_lock_path = RBS::Collection::Config.to_lockfile_path(RBS::Collection::Config::PATH)
72
+ repository_prefix = Pathname("tmp/rbs-src")
73
+ rbs_prefix = Pathname("sig/rbs-src")
74
+
75
+ OptionParser.new do |opts|
76
+ opts.on("--rbs-collection-lock=PATH", "The path to rbs_collection.lock.yaml (default: #{rbs_collection_lock_path})") { rbs_collection_lock_path = Pathname(_1) }
77
+ opts.on("--repo-prefix=PREFIX", "The location to put repository in (default: #{repository_prefix})") { repository_prefix = Pathname(_1) }
78
+ opts.on("--rbs-prefix=PREFIX", "The location to put symlinks in (default: #{rbs_prefix})") { rbs_prefix = Pathname(_1) }
79
+
80
+ opts.banner = <<~BANNER
81
+ Usage: rbs-src setup [options]
82
+
83
+ Set up git repositories and symlinks in rbs_collection.yaml.
84
+
85
+ Example:
86
+ $ rbs-src setup
87
+
88
+ Options:
89
+ BANNER
90
+
91
+ end.parse!(argv)
92
+
93
+ rbs_prefix.mkpath
94
+ rbs_prefix.mkpath
95
+
96
+ lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
97
+ lockfile_path: rbs_collection_lock_path,
98
+ data: YAML.safe_load(rbs_collection_lock_path.read)
99
+ )
100
+
101
+ loader = LockfileLoader.new(
102
+ lockfile: lockfile,
103
+ repository_prefix: repository_prefix,
104
+ rbs_prefix: rbs_prefix
105
+ )
106
+
107
+ runner = CommandRunner.new(stdout: STDOUT)
108
+
109
+ loader.each_gem do |gem, repo, commit|
110
+ runner.push "Setting up #{gem.name}-#{gem.version}" do
111
+ runner.push "Cloning git repository into #{gem.repository_root}" do
112
+ if gem.repository_root.directory?
113
+ runner.puts "Skipping already exist"
114
+ else
115
+ gem.clone(runner, repository_url: repo, commit: commit)
116
+ end
117
+ end
118
+
119
+ runner.push "Linking to #{gem.rbs_path}" do
120
+ unless gem.repository_path.exist?
121
+ runner.puts "File.symlink..."
122
+ gem.link()
123
+ else
124
+ runner.puts "Skipping already exist"
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ other_libs = [] #: Array[[String, String]]
131
+ lockfile.gems.each_value do |gem|
132
+ case source = gem[:source]
133
+ when RBS::Collection::Sources::Git
134
+ # skip
135
+ else
136
+ other_libs << [gem[:name], gem[:version]]
137
+ end
138
+ end
139
+
140
+ other_libs.sort_by! { _1[0] }
141
+
142
+ unless other_libs.empty?
143
+ runner.push "Load other libraries yourself:" do
144
+ if has_gem?("steep")
145
+ runner.puts "Put the following lines in your Steepfile:"
146
+
147
+ other_libs.each do |name, version|
148
+ runner.puts " library('#{name}')"
149
+ end
150
+ else
151
+ other_libs.each do |name, version|
152
+ runner.puts "-r #{name} \\"
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ 0
159
+ else
160
+ puts "Unknown command: #{command}"
161
+ puts
162
+ puts " known commands: setup, link"
163
+ 1
164
+ end
165
+ end
166
+
167
+ def self.has_gem?(name)
168
+ ::Gem::Specification.find_by_name(name)
169
+ true
170
+ rescue
171
+ false
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,42 @@
1
+ module Rbs
2
+ module Src
3
+ class CommandRunner
4
+ attr_reader :stdout
5
+
6
+ def initialize(stdout:)
7
+ @stdout = stdout
8
+ @level = 0
9
+ end
10
+
11
+ def puts(message)
12
+ prefix = " " * @level
13
+ stdout.puts "#{prefix}#{message}"
14
+ end
15
+
16
+ def push(message)
17
+ puts "⏩️ #{message}"
18
+ begin
19
+ @level += 1
20
+ yield
21
+ ensure
22
+ @level -= 1
23
+ end
24
+ end
25
+
26
+ def execute!(*command, chdir: Pathname.pwd)
27
+ # @type var out: String
28
+ # @type var status: Process::Status
29
+
30
+ out, status = Open3.capture2e(*command, chdir: chdir)
31
+
32
+ unless status.success?
33
+ puts "🚨 Command failed: #{command.inspect} in #{chdir}..."
34
+ out.each_line do |line|
35
+ puts "| #{line}"
36
+ end
37
+ raise status.inspect
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ module Rbs
2
+ module Src
3
+ class Gem
4
+ attr_reader :name, :version, :repository_prefix, :repository_dir, :rbs_prefix
5
+
6
+ def initialize(name:, version:, repository_prefix:, repository_dir:, rbs_prefix:)
7
+ @name = name
8
+ @version = version
9
+ @repository_prefix = repository_prefix
10
+ @repository_dir = repository_dir
11
+ @rbs_prefix = rbs_prefix
12
+ end
13
+
14
+ def repository_root
15
+ repository_prefix + "#{name}-#{version}"
16
+ end
17
+
18
+ def repository_path
19
+ repository_root.join(repository_dir, name, version)
20
+ end
21
+
22
+ def rbs_path
23
+ rbs_prefix + "#{name}-#{version}"
24
+ end
25
+
26
+ def clone(runner, repository_url:, commit:)
27
+ runner.puts "git clone..."
28
+ runner.execute!("git", "clone", "--filter=blob:none", repository_url, repository_root.to_s)
29
+ if commit
30
+ runner.puts "git checkout..."
31
+ runner.execute!("git", "checkout", commit, chdir: repository_root)
32
+ end
33
+ end
34
+
35
+ def link
36
+ File.symlink(repository_path.relative_path_from(rbs_path.parent), rbs_path)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ module Rbs
2
+ module Src
3
+ class LockfileLoader
4
+ attr_reader :lockfile, :repository_prefix, :rbs_prefix
5
+
6
+ def initialize(lockfile:, repository_prefix:, rbs_prefix:)
7
+ @lockfile = lockfile
8
+ @repository_prefix = repository_prefix
9
+ @rbs_prefix = rbs_prefix
10
+ end
11
+
12
+ def each_gem()
13
+ lockfile.gems.each_value do |library|
14
+ case source = library[:source]
15
+ when RBS::Collection::Sources::Git
16
+ gem = Gem.new(
17
+ name: library[:name],
18
+ version: library[:version],
19
+ repository_prefix: repository_prefix,
20
+ repository_dir: Pathname(source.repo_dir),
21
+ rbs_prefix: rbs_prefix
22
+ )
23
+
24
+ yield gem, source.remote, source.revision
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rbs
4
+ module Src
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/rbs/src.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "src/version"
4
+
5
+ require "rbs"
6
+ require "open3"
7
+
8
+ require "rbs/src/gem"
9
+ require "rbs/src/lockfile_loader"
10
+ require "rbs/src/command_runner"
@@ -0,0 +1,106 @@
1
+ ---
2
+ sources:
3
+ - type: git
4
+ name: ruby/gem_rbs_collection
5
+ revision: aeede7258d020bfd509541e0c8075ce833292409
6
+ remote: https://github.com/ruby/gem_rbs_collection.git
7
+ repo_dir: gems
8
+ path: ".gem_rbs_collection"
9
+ gems:
10
+ - name: abbrev
11
+ version: '0'
12
+ source:
13
+ type: stdlib
14
+ - name: activesupport
15
+ version: '6.0'
16
+ source:
17
+ type: git
18
+ name: ruby/gem_rbs_collection
19
+ revision: aeede7258d020bfd509541e0c8075ce833292409
20
+ remote: https://github.com/ruby/gem_rbs_collection.git
21
+ repo_dir: gems
22
+ - name: concurrent-ruby
23
+ version: '1.1'
24
+ source:
25
+ type: git
26
+ name: ruby/gem_rbs_collection
27
+ revision: aeede7258d020bfd509541e0c8075ce833292409
28
+ remote: https://github.com/ruby/gem_rbs_collection.git
29
+ repo_dir: gems
30
+ - name: date
31
+ version: '0'
32
+ source:
33
+ type: stdlib
34
+ - name: dbm
35
+ version: '0'
36
+ source:
37
+ type: stdlib
38
+ - name: i18n
39
+ version: '1.10'
40
+ source:
41
+ type: git
42
+ name: ruby/gem_rbs_collection
43
+ revision: aeede7258d020bfd509541e0c8075ce833292409
44
+ remote: https://github.com/ruby/gem_rbs_collection.git
45
+ repo_dir: gems
46
+ - name: json
47
+ version: '0'
48
+ source:
49
+ type: stdlib
50
+ - name: logger
51
+ version: '0'
52
+ source:
53
+ type: stdlib
54
+ - name: minitest
55
+ version: '0'
56
+ source:
57
+ type: stdlib
58
+ - name: monitor
59
+ version: '0'
60
+ source:
61
+ type: stdlib
62
+ - name: mutex_m
63
+ version: '0'
64
+ source:
65
+ type: stdlib
66
+ - name: optparse
67
+ version: '0'
68
+ source:
69
+ type: stdlib
70
+ - name: pathname
71
+ version: '0'
72
+ source:
73
+ type: stdlib
74
+ - name: pstore
75
+ version: '0'
76
+ source:
77
+ type: stdlib
78
+ - name: rbs
79
+ version: 3.1.2
80
+ source:
81
+ type: rubygems
82
+ - name: rdoc
83
+ version: '0'
84
+ source:
85
+ type: stdlib
86
+ - name: securerandom
87
+ version: '0'
88
+ source:
89
+ type: stdlib
90
+ - name: singleton
91
+ version: '0'
92
+ source:
93
+ type: stdlib
94
+ - name: time
95
+ version: '0'
96
+ source:
97
+ type: stdlib
98
+ - name: tsort
99
+ version: '0'
100
+ source:
101
+ type: stdlib
102
+ - name: yaml
103
+ version: '0'
104
+ source:
105
+ type: stdlib
106
+ gemfile_lock_path: Gemfile.lock
@@ -0,0 +1,20 @@
1
+ # Download sources
2
+ sources:
3
+ - type: git
4
+ name: ruby/gem_rbs_collection
5
+ remote: https://github.com/ruby/gem_rbs_collection.git
6
+ revision: main
7
+ repo_dir: gems
8
+
9
+ # You can specify local directories as sources also.
10
+ # - type: local
11
+ # path: path/to/your/local/repository
12
+
13
+ # A directory to install the downloaded RBSs
14
+ path: .gem_rbs_collection
15
+
16
+ gems:
17
+ - name: pathname
18
+ - name: yaml
19
+ - name: activesupport
20
+ version: 6.0
data/sig/rbs/cli.rbs ADDED
@@ -0,0 +1,9 @@
1
+ module Rbs
2
+ module Src
3
+ class CLI
4
+ def self.start: (Array[String]) -> Integer
5
+
6
+ def self.has_gem?: (String) -> bool
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Rbs
2
+ module Src
3
+ class CommandRunner
4
+ attr_reader stdout: IO
5
+
6
+ @level: Integer
7
+
8
+ def initialize: (stdout: IO) -> void
9
+
10
+ def push: (String message) { () -> void } -> void
11
+
12
+ def puts: (String) -> void
13
+
14
+ def execute!: (*String, ?chdir: Pathname) -> void
15
+ end
16
+ end
17
+ end
data/sig/rbs/gem.rbs ADDED
@@ -0,0 +1,29 @@
1
+ module Rbs
2
+ module Src
3
+ class Gem
4
+ attr_reader name: String
5
+
6
+ attr_reader version: String
7
+
8
+ attr_reader repository_prefix: Pathname
9
+
10
+ attr_reader repository_dir: Pathname
11
+
12
+ attr_reader rbs_prefix: Pathname
13
+
14
+ def initialize: (name: String, version: String, repository_prefix: Pathname, repository_dir: Pathname, rbs_prefix: Pathname) -> void
15
+
16
+ def repository_root: () -> Pathname
17
+
18
+ # The path of the directory in the `#repository_prefix` that contains the RBS files of the gem
19
+ def repository_path: () -> Pathname
20
+
21
+ # The path of the directory in the `#rbs_prefix` that contains the RBS files of the gem
22
+ def rbs_path: () -> Pathname
23
+
24
+ def clone: (CommandRunner, repository_url: String, commit: String?) -> void
25
+
26
+ def link: () -> void
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ use RBS::Collection::Config::Lockfile
2
+
3
+ module Rbs
4
+ module Src
5
+ class LockfileLoader
6
+ attr_reader lockfile: Lockfile
7
+
8
+ attr_reader repository_prefix: Pathname
9
+
10
+ attr_reader rbs_prefix: Pathname
11
+
12
+ def initialize: (lockfile: Lockfile, repository_prefix: Pathname, rbs_prefix: Pathname) -> void
13
+
14
+ def each_gem: () { (Gem, String git_repository_url, String commit) -> void } -> void
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Rbs
2
+ module Src
3
+ class RemoteSource
4
+ attr_reader repository_url: String
5
+
6
+ attr_reader commit: String
7
+
8
+ def initialize: (repository_url: String, commit: String) -> void
9
+ end
10
+ end
11
+ end
data/sig/rbs/src.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module Rbs
2
+ module Src
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbs-src
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Soutaro Matsumoto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: rbs-src
14
+ email:
15
+ - matsumoto@soutaro.com
16
+ executables:
17
+ - rbs-src
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CODE_OF_CONDUCT.md
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - Steepfile
28
+ - exe/rbs-src
29
+ - lib/rbs/src.rb
30
+ - lib/rbs/src/cli.rb
31
+ - lib/rbs/src/command_runner.rb
32
+ - lib/rbs/src/gem.rb
33
+ - lib/rbs/src/lockfile_loader.rb
34
+ - lib/rbs/src/version.rb
35
+ - rbs_collection.lock.yaml
36
+ - rbs_collection.yaml
37
+ - sig/rbs/cli.rbs
38
+ - sig/rbs/command_runner.rbs
39
+ - sig/rbs/gem.rbs
40
+ - sig/rbs/lockfile_loader.rbs
41
+ - sig/rbs/remote_source.rbs
42
+ - sig/rbs/src.rbs
43
+ homepage: https://github.com/soutaro/rbs-src
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/soutaro/rbs-src
48
+ source_code_uri: https://github.com/soutaro/rbs-src.git
49
+ changelog_uri: https://github.com/soutaro/rbs-src
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.6.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.4.10
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: rbs-src
69
+ test_files: []