subbundle 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 944f9c330643b53a08e92f77dc13aef3a078624190df3b314e563e4b7fbe7cef
4
+ data.tar.gz: cd1e370434bfba747791ba249f9ab596046d816a4c09707d903658a92bc7ebdf
5
+ SHA512:
6
+ metadata.gz: 6b6b5786910f05b1c073842058a9daddcd28637b5793b3096402ea8827dad1578f7c4ffa126e94b5d27fcbe31f8afbafef4e56dfb894faa813d75e8ecceb77cd
7
+ data.tar.gz: 9d70f746de832555e29117815a6a686f0a823cd1afd453d219c8aab4cf843a2525873be0e13cc071b021d093e7cba725756230a2865dc4b50665ec7de9a694f1
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Subbundle
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/subbundle`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'subbundle'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install subbundle
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ngan/subbundle. 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/ngan/subbundle/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Subbundle project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ngan/subbundle/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Subbundle
4
+ VERSION = "0.1.0"
5
+ end
data/lib/subbundle.rb ADDED
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "subbundle/version"
4
+
5
+ module Subbundle
6
+ def self.setup(*gems, name: nil)
7
+ require "bundler"
8
+ require "digest/md5"
9
+
10
+ name ||= File.basename($PROGRAM_NAME)
11
+ gems = gems.map(&:to_s)
12
+
13
+ digest = Digest::MD5.new
14
+ digest << Bundler.default_lockfile.to_s
15
+ digest.file(Bundler.default_lockfile)
16
+ gems.sort.each { |dep| digest << dep }
17
+
18
+ subbundle_lockfile_path = Bundler.app_config_path.join("subbundles/#{name}.#{digest.hexdigest}.lock")
19
+
20
+ if subbundle_lockfile_path.exist?
21
+ return if setup_from_subbundle(gems, subbundle_lockfile_path)
22
+ end
23
+
24
+ default_lockfile = Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))
25
+ required_dependencies = default_lockfile.dependencies.slice(*gems).values
26
+ spec_set = Bundler::SpecSet.new(default_lockfile.specs)
27
+ specs = spec_set.for(required_dependencies, false, true)
28
+ dependencies = default_lockfile.dependencies.slice(*specs.map(&:name)).values
29
+ source_list = build_source_list(specs.map(&:source).uniq)
30
+ definition = Bundler::Definition.new(Bundler.default_lockfile, dependencies, source_list, {})
31
+ subbundle_lockfile_path.dirname.mkpath
32
+ subbundle_lockfile_path.write(Bundler.ui.silence { definition.to_lock })
33
+
34
+ setup_from_subbundle(gems, subbundle_lockfile_path)
35
+ end
36
+
37
+ def self.setup_from_subbundle(gems, subbundle_lockfile_path)
38
+ subbundle_lockfile = Bundler::LockfileParser.new(Bundler.read_file(subbundle_lockfile_path))
39
+ dependencies = subbundle_lockfile.dependencies.slice(*gems).values
40
+ source_list = build_source_list(subbundle_lockfile.sources)
41
+ definition = Bundler::Definition.new(subbundle_lockfile_path, dependencies, source_list, {})
42
+ if definition.nothing_changed?
43
+ setup_runtime(definition)
44
+ true
45
+ else
46
+ subbundle_lockfile_path.delete
47
+ false
48
+ end
49
+ end
50
+
51
+ def self.build_source_list(sources)
52
+ sources.compact.each_with_object(Bundler::SourceList.new) do |source, source_list|
53
+ case source
54
+ when Bundler::Source::Git
55
+ source_list.add_git_source(source.options)
56
+ when Bundler::Source::Path, Bundler::Source::Gemspec
57
+ source_list.add_path_source(source.options)
58
+ when Bundler::Source::Rubygems
59
+ next if source.remotes.empty?
60
+ source_list.add_rubygems_source(source.options)
61
+ else
62
+ raise "unhandled: #{source.inspect}"
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.setup_runtime(definition)
68
+ Bundler.ui.silence { Bundler::Runtime.new(Bundler.root, definition).setup }
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subbundle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ngan Pham
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - ngan@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - lib/subbundle.rb
22
+ - lib/subbundle/version.rb
23
+ homepage: https://github.com/bigrails/subbundle
24
+ licenses:
25
+ - MIT
26
+ metadata:
27
+ allowed_push_host: https://rubygems.org
28
+ homepage_uri: https://github.com/bigrails/subbundle
29
+ source_code_uri: https://github.com/bigrails/subbundle
30
+ changelog_uri: https://github.com/bigrails/subbundle/releases
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.6.0
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.2.32
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Creates a subbundle from your project's bundle.
50
+ test_files: []