bundler-inject 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 834b4bd13923ff8caf120998b70f6c4e1daa653892846b6e6fc20fbd614f8963
4
+ data.tar.gz: faa0f483d05511d3bfdac39a87c4cb0f9a8b2ac3b3a3fe02c650c013090f4acb
5
+ SHA512:
6
+ metadata.gz: a39735242f3323779362935234af1dbeac7eba4b307a0b4f9a497139a3cd06a07cb03d9e52202e72f25a535b51b3b61c34de5d2bf121ea15ec24e628b40f746b
7
+ data.tar.gz: 89411f99b21e2b814e36818cee44dd7e5f359080607d497c647789e8208bb76c059d82af5bfb0b8223166dc4be4badf60e0bd3def1b795e974f8f7dd76bdaca2
@@ -0,0 +1,30 @@
1
+ ---
2
+ version: '2'
3
+ prepare:
4
+ fetch:
5
+ - url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
6
+ path: ".rubocop_base.yml"
7
+ - url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml
8
+ path: ".rubocop_cc_base.yml"
9
+ checks:
10
+ argument-count:
11
+ enabled: false
12
+ complex-logic:
13
+ enabled: false
14
+ file-lines:
15
+ enabled: false
16
+ method-complexity:
17
+ config:
18
+ threshold: 11
19
+ method-count:
20
+ enabled: false
21
+ method-lines:
22
+ enabled: false
23
+ nested-control-flow:
24
+ enabled: false
25
+ return-statements:
26
+ enabled: false
27
+ plugins:
28
+ rubocop:
29
+ enabled: true
30
+ config: ".rubocop_cc.yml"
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --order random
@@ -0,0 +1,3 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
3
+ - .rubocop_local.yml
@@ -0,0 +1,4 @@
1
+ inherit_from:
2
+ - .rubocop_base.yml
3
+ - .rubocop_cc_base.yml
4
+ - .rubocop_local.yml
File without changes
@@ -0,0 +1,21 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.4.5
6
+ - 2.5.3
7
+ env:
8
+ - TEST_BUNDLER_VERSION=1.15
9
+ - TEST_BUNDLER_VERSION=1.16
10
+ - TEST_BUNDLER_VERSION=1.17
11
+ - TEST_BUNDLER_VERSION=2.0
12
+ before_install:
13
+ - 'echo ''gem: --no-ri --no-rdoc --no-document'' > ~/.gemrc'
14
+ - gem install bundler -v "~> $TEST_BUNDLER_VERSION.0"
15
+ before_script:
16
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
17
+ > ./cc-test-reporter
18
+ - chmod +x ./cc-test-reporter
19
+ - "./cc-test-reporter before-build"
20
+ after_script:
21
+ - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bundler-inject.gemspec
6
+ gemspec
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,151 @@
1
+ # bundler-inject
2
+
3
+ [![Build Status](https://travis-ci.org/ManageIQ/bundler-inject.svg?branch=master)](https://travis-ci.org/ManageIQ/bundler-inject)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e4650d6dd7cbcd981057/maintainability)](https://codeclimate.com/github/ManageIQ/bundler-inject/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/e4650d6dd7cbcd981057/test_coverage)](https://codeclimate.com/github/ManageIQ/bundler-inject/test_coverage)
6
+ [![Security](https://hakiri.io/github/ManageIQ/bundler-inject/master.svg)](https://hakiri.io/github/ManageIQ/bundler-inject/master)
7
+
8
+ **bundler-inject** is a [bundler plugin](https://bundler.io/guides/bundler_plugins.html)
9
+ that allows a developer to extend a project with their own personal gems and/or
10
+ override existing gems, without having to modify the Gemfile, thus avoiding
11
+ accidental modification of git history.
12
+
13
+ ## Installation
14
+
15
+ Add these lines to your application's `Gemfile`:
16
+
17
+ ```ruby
18
+ plugin 'bundler-inject'
19
+ require File.join(Bundler::Plugin.index.load_paths("bundler-inject")[0], "bundler-inject") rescue nil
20
+ ```
21
+
22
+ Additionally, commit a `bundler.d/.gitkeep` file, and add `/bundler.d` to your
23
+ `.gitignore` file. This will be one of the locations developers can place their
24
+ overrides.
25
+
26
+ ## Usage
27
+
28
+ Once the above lines are in the Gemfile, subsequent bundle commands will attempt
29
+ to evaluate extra gemfiles from two locations if they are present.
30
+
31
+ - global - `~/.bundler.d/*.rb`
32
+ - project - `$PROJECT_DIR/bundler.d/*.rb`
33
+
34
+ For example, a developer may prefer the `pry` gem over `irb`, but can't use it
35
+ because the project Gemfile doesn't have `pry` in it. Instead of modifying the
36
+ Gemfile and hoping they don't commit the changes, they can create a
37
+ `bundler.d/developer.rb` file with the contents set to `gem "pry"`. From then on
38
+ the developer can use `pry`, even though the project didn't state it explicitly.
39
+
40
+ Since this example developer likely *always* wants to use `pry`, it would be
41
+ preferable to specify this as a global choice in a `~/.bundler.d/developer.rb`
42
+ file instead.
43
+
44
+ ### override_gem
45
+
46
+ `override_gem` is an extra DSL command that allows overriding existing gems from
47
+ the Gemfile. A useful example of this is if you are making a change to a
48
+ dependent gem, and temporarily want to override the existing `gem` definition
49
+ with, a git or path reference.
50
+
51
+ For example, there is a project with a Gemfile with `gem "foo"` in it. We want
52
+ to fix a bug in foo, and we intend to make a pull request to upstream, but in
53
+ the interim we want to test our foo change with the project. Instead of
54
+ modifying the Gemfile and hoping we don't commit the changes, we can create a
55
+ `bundler.d/developer.rb` with the contents set to
56
+ `override_gem "foo", :git => "https://github.com/me/foo.git"`. bundler-inject
57
+ will output a warning to the screen to make us aware we are overriding, and
58
+ then it will use the new definition.
59
+
60
+ `override_gem` will raise an exception if the specified gem does not exist in
61
+ the original Gemfile.
62
+
63
+ ### ensure_gem
64
+
65
+ `ensure_gem` is an extra DSL command similar to `override_gem`, and primarily
66
+ meant for the global override file.
67
+
68
+ One issue with the global file is that it specifies a new gem with `gem`, but
69
+ that gem already exists in the project you will get a nasty warning. Conversely,
70
+ if it specifies an override with `override_gem`, but the gem does not exist in
71
+ the project you will get an exception. To deal with these issues, you can use
72
+ `ensure_gem` in your global file.
73
+
74
+ `ensure_gem` works by checking if the gem is already in the dependency list, and
75
+ comparing the options specified. If the dependency does not exist, it uses `gem`,
76
+ otherwise if the options or version specified are significantly different, it
77
+ will use `override_gem`, otherwise it will just do nothing, deferring to the
78
+ original declaration.
79
+
80
+ ## What is this sorcery?
81
+
82
+ While this is technically a bundler plugin, bundler-inject does not use the
83
+ expected plugin hooks/sources/commands. To understand how this works and why
84
+ these were not used, it's useful to understand how bundler passes over your
85
+ Gemfile.
86
+
87
+ For `bundle install`/`bundle update`, bundler makes two passes over the Gemfile.
88
+
89
+ On the first pass, bundler executes your Gemfile in a `Bundler::Plugin::DSL`
90
+ context. This class is a special subclass of `Bundler::Dsl`, where nearly all of
91
+ the usual DSL methods like `gem` and `gemspec` are a no-op, and the `plugin` DSL
92
+ method does it's thing. So, after the first pass, bundler sees only your plugin
93
+ gems, and will then install them into `.bundle/plugin`.
94
+
95
+ On the second pass, bundler executes your Gemfile in a `Bundler::Dsl` context,
96
+ where the usual DSL methods like `gem` and `gemspec` do their thing, and the
97
+ `plugin` DSL method is instead a no-op. This is the pass most people think of.
98
+
99
+ On the very first install of the plugin, between the two passes, bundler will
100
+ load your plugin to see what kind of features it has, whether hooks, sources, or
101
+ commands, and will store this information in the `.bundle/plugin/index` file.
102
+ It would seem that since the plugin code is loaded this would be an opportune
103
+ time to do what we need, but unfortunately this only happens on initial install.
104
+ On subsequent `bundle update` calls, bundler sees that the index file exists,
105
+ and doesn't need to load the plugin, since all of the information is in the
106
+ index.
107
+
108
+ Complicating the matter further, for `bundle check`/`bundle exec`, bundler makes
109
+ only one pass over the Gemfile in a `Bundler::Dsl` context.
110
+
111
+ One immediate question on your mind may be, why not just define a fake hook or
112
+ source, and then put the code in there. Unfortunately, the problem is that any
113
+ of hooks, sources, or commands that will trigger the load of the plugin occur
114
+ after the Gemfile has already been passed over, preventing us from adding to the
115
+ DSL, as well as loading extra gemfiles.
116
+
117
+ As such, the earliest we can possibly trigger our plugin load in all cases is
118
+ immediately after we declare the plugin in the Gemfile. This is why we need that
119
+ magic line after the plugin line in the Gemfile.
120
+
121
+ Once we have the ability to trigger a load of our plugin, whether direct via the
122
+ magic line, or automatically on first plugin installation, then the plugin can
123
+ manipulate the Bundler::Dsl to add the `override_gem` method and trigger the
124
+ eval of extra gemfiles.
125
+
126
+ ## Development
127
+
128
+ Development of bundler plugins can be a little strange, with a few gotchas.
129
+
130
+ 1. bundler installs your gem into the .bundle/plugin directory of the target
131
+ project.
132
+ 2. `plugin "bundler-inject", :path => "/path/to/bundler-inject"` doesn't work
133
+ as expected since bundler needs to "install" your gem into .bundle/plugin,
134
+ and thus doesn't know how. To get around this, use
135
+ `:git => File.expand_path("/path/to/bundler-inject")`.
136
+ 3. If you are using :git (which also applies to :path with the workaround
137
+ above), bundler will only consider committed code. Therefore, you *must*
138
+ commit your code in a temporary commit if you want it to be picked up.
139
+ 4. bundler plugins are copied to .bundle/plugin only on first install, and then
140
+ updated only if a change is detected. Unless you have a `:ref` or a changing
141
+ version number, bundler will think your gem hasn't changed and will not
142
+ update it, even if you commit something. To force bundler to pull in your
143
+ changes, you will have to `rm -rf .bundle/plugin`.
144
+
145
+ ## Contributing
146
+
147
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ManageIQ/bundler-inject.
148
+
149
+ ## License
150
+
151
+ This project is available as open source under the terms of the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bundler/inject"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "bundler/inject/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bundler-inject"
7
+ spec.version = Bundler::Inject::VERSION
8
+ spec.authors = ["ManageIQ Authors"]
9
+
10
+ spec.summary = %q{A bundler plugin that allows extension of a project with personal and overridden gems}
11
+ spec.description = %q{bundler-inject is a bundler plugin that allows a developer to extend a project with their own personal gems and/or override existing gems, without having to modify the Gemfile, thus avoiding accidental modification of git history.}
12
+ spec.homepage = "https://github.com/ManageIQ/bundler-inject"
13
+ spec.license = "Apache-2.0"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "colorize"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "simplecov"
29
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(__dir__) unless $LOAD_PATH.include?(__dir__)
2
+ require 'bundler/inject'
@@ -0,0 +1,7 @@
1
+ require "bundler/inject/version"
2
+ require "bundler/inject/dsl_patch"
3
+
4
+ Bundler::Dsl.prepend(Bundler::Inject::DslPatch)
5
+ ObjectSpace.each_object(Bundler::Dsl) do |o|
6
+ o.singleton_class.prepend(Bundler::Inject::DslPatch)
7
+ end
@@ -0,0 +1,100 @@
1
+ module Bundler
2
+ module Inject
3
+ module DslPatch
4
+ def override_gem(name, *args)
5
+ raise "Trying to override unknown gem #{name.inspect}" unless (dependency = find_dependency(name.to_s))
6
+
7
+ calling_loc = caller_locations.detect { |loc| !loc.path.include?("lib/bundler") }
8
+ calling_file = "#{calling_loc.path}:#{calling_loc.lineno}"
9
+
10
+ remove_dependencies_and_sources(dependency)
11
+ expand_gem_path(args, calling_file)
12
+ gem(name, *args).tap do
13
+ warn_override_gem(calling_file, name, args)
14
+ end
15
+ end
16
+
17
+ def ensure_gem(name, *args)
18
+ current = find_dependency(name)
19
+ if !current
20
+ gem(name, *args)
21
+ else
22
+ version, opts = extract_version_opts(args)
23
+ version = [">= 0"] if version.empty?
24
+ if opts.any? || (version != [">= 0"] && Gem::Requirement.new(version) != current.requirement)
25
+ override_gem(name, *args)
26
+ end
27
+ end
28
+ end
29
+
30
+ def to_definition(lockfile, unlock)
31
+ calling_loc = caller_locations(1, 1).first
32
+ if calling_loc.path.include?("bundler/dsl.rb") && calling_loc.base_label == "evaluate"
33
+ load_global_bundler_d
34
+
35
+ # @gemfiles doesn't exist on Bundler <= 1.15, and we can't get at @gemfile
36
+ # by this point, but there's a high probability it's just "Gemfile",
37
+ # or slightly more accurately, the lockfile name without the ".lock" bit.
38
+ targets = defined?(@gemfiles) ? @gemfiles : [Pathname.new(lockfile.to_s.chomp(".lock"))]
39
+
40
+ targets.reverse_each do |gemfile|
41
+ load_local_bundler_d(File.dirname(gemfile))
42
+ end
43
+ end
44
+ super
45
+ end
46
+
47
+ private
48
+
49
+ def find_dependency(name)
50
+ dependencies.find { |d| d.name == name }
51
+ end
52
+
53
+ def remove_dependencies_and_sources(dependency)
54
+ removed_dependency = dependencies.delete(dependency)
55
+ if removed_dependency.source.kind_of?(Bundler::Source::Git)
56
+ @sources.send(:source_list_for, removed_dependency.source).delete_if do |other_source|
57
+ removed_dependency.source == other_source
58
+ end
59
+ end
60
+ end
61
+
62
+ def expand_gem_path(args, calling_file)
63
+ return unless args.last.kind_of?(Hash) && args.last[:path]
64
+ args.last[:path] = File.expand_path(args.last[:path], File.dirname(calling_file))
65
+ end
66
+
67
+ def extract_version_opts(args)
68
+ args.last.is_a?(Hash) ? [args[0..-2], args[-1]] : [args, {}]
69
+ end
70
+
71
+ def warn_override_gem(calling_file, name, args)
72
+ return if ENV["RAILS_ENV"] == "production"
73
+
74
+ version, opts = extract_version_opts(args)
75
+ message = "** override_gem(#{name.inspect}"
76
+ message << ", #{version.inspect[1..-2]}" unless version.empty?
77
+ message << ", #{opts.inspect[1..-2]}" unless opts.empty?
78
+ message << ") at #{calling_file}"
79
+ message = "\e[33m#{message}\e[0m" if $stdout.tty?
80
+
81
+ warn message
82
+ end
83
+
84
+ def load_global_bundler_d
85
+ load_bundler_d(File.join(Dir.home, ".bundler.d"))
86
+ end
87
+
88
+ def load_local_bundler_d(dir)
89
+ load_bundler_d(File.join(dir, "bundler.d"))
90
+ end
91
+
92
+ def load_bundler_d(dir)
93
+ Dir.glob(File.join(dir, '*.rb')).sort.each do |f|
94
+ Bundler.ui.debug "Injecting #{f}..."
95
+ eval_gemfile(f)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,5 @@
1
+ module Bundler
2
+ module Inject
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'bundler-inject'
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler-inject
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ManageIQ Authors
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-05 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: bundler-inject is a bundler plugin that allows a developer to extend
84
+ a project with their own personal gems and/or override existing gems, without having
85
+ to modify the Gemfile, thus avoiding accidental modification of git history.
86
+ email:
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".codeclimate.yml"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".rubocop_cc.yml"
96
+ - ".rubocop_local.yml"
97
+ - ".travis.yml"
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - bundler-inject.gemspec
105
+ - lib/bundler-inject.rb
106
+ - lib/bundler/inject.rb
107
+ - lib/bundler/inject/dsl_patch.rb
108
+ - lib/bundler/inject/version.rb
109
+ - plugins.rb
110
+ homepage: https://github.com/ManageIQ/bundler-inject
111
+ licenses:
112
+ - Apache-2.0
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: A bundler plugin that allows extension of a project with personal and overridden
134
+ gems
135
+ test_files: []