bundler-clone 4.0.15
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 +7 -0
- data/CHANGELOG.md +5670 -0
- data/LICENSE.md +22 -0
- data/README.md +58 -0
- data/bundler.gemspec +46 -0
- data/exe/bundle +29 -0
- data/exe/bundler +4 -0
- data/lib/bundler/.document +1 -0
- data/lib/bundler/build_metadata.rb +44 -0
- data/lib/bundler/capistrano.rb +4 -0
- data/lib/bundler/checksum.rb +270 -0
- data/lib/bundler/ci_detector.rb +75 -0
- data/lib/bundler/cli/add.rb +62 -0
- data/lib/bundler/cli/binstubs.rb +57 -0
- data/lib/bundler/cli/cache.rb +32 -0
- data/lib/bundler/cli/check.rb +40 -0
- data/lib/bundler/cli/clean.rb +25 -0
- data/lib/bundler/cli/common.rb +161 -0
- data/lib/bundler/cli/config.rb +208 -0
- data/lib/bundler/cli/console.rb +47 -0
- data/lib/bundler/cli/doctor/diagnose.rb +167 -0
- data/lib/bundler/cli/doctor/ssl.rb +249 -0
- data/lib/bundler/cli/doctor.rb +33 -0
- data/lib/bundler/cli/exec.rb +114 -0
- data/lib/bundler/cli/fund.rb +36 -0
- data/lib/bundler/cli/gem.rb +493 -0
- data/lib/bundler/cli/info.rb +83 -0
- data/lib/bundler/cli/init.rb +51 -0
- data/lib/bundler/cli/install.rb +127 -0
- data/lib/bundler/cli/issue.rb +41 -0
- data/lib/bundler/cli/list.rb +97 -0
- data/lib/bundler/cli/lock.rb +94 -0
- data/lib/bundler/cli/open.rb +29 -0
- data/lib/bundler/cli/outdated.rb +337 -0
- data/lib/bundler/cli/platform.rb +48 -0
- data/lib/bundler/cli/plugin.rb +39 -0
- data/lib/bundler/cli/pristine.rb +64 -0
- data/lib/bundler/cli/remove.rb +17 -0
- data/lib/bundler/cli/show.rb +71 -0
- data/lib/bundler/cli/update.rb +125 -0
- data/lib/bundler/cli.rb +829 -0
- data/lib/bundler/compact_index_client/cache.rb +96 -0
- data/lib/bundler/compact_index_client/cache_file.rb +148 -0
- data/lib/bundler/compact_index_client/parser.rb +87 -0
- data/lib/bundler/compact_index_client/updater.rb +105 -0
- data/lib/bundler/compact_index_client.rb +92 -0
- data/lib/bundler/constants.rb +14 -0
- data/lib/bundler/current_ruby.rb +94 -0
- data/lib/bundler/definition.rb +1304 -0
- data/lib/bundler/dependency.rb +151 -0
- data/lib/bundler/deployment.rb +6 -0
- data/lib/bundler/deprecate.rb +44 -0
- data/lib/bundler/digest.rb +71 -0
- data/lib/bundler/dsl.rb +642 -0
- data/lib/bundler/endpoint_specification.rb +184 -0
- data/lib/bundler/env.rb +148 -0
- data/lib/bundler/environment_preserver.rb +69 -0
- data/lib/bundler/errors.rb +277 -0
- data/lib/bundler/feature_flag.rb +20 -0
- data/lib/bundler/fetcher/base.rb +55 -0
- data/lib/bundler/fetcher/compact_index.rb +133 -0
- data/lib/bundler/fetcher/dependency.rb +85 -0
- data/lib/bundler/fetcher/downloader.rb +116 -0
- data/lib/bundler/fetcher/gem_remote_fetcher.rb +24 -0
- data/lib/bundler/fetcher/index.rb +25 -0
- data/lib/bundler/fetcher.rb +365 -0
- data/lib/bundler/force_platform.rb +16 -0
- data/lib/bundler/friendly_errors.rb +127 -0
- data/lib/bundler/gem_helper.rb +237 -0
- data/lib/bundler/gem_tasks.rb +7 -0
- data/lib/bundler/gem_version_promoter.rb +147 -0
- data/lib/bundler/index.rb +203 -0
- data/lib/bundler/injector.rb +284 -0
- data/lib/bundler/inline.rb +106 -0
- data/lib/bundler/installer/gem_installer.rb +88 -0
- data/lib/bundler/installer/parallel_installer.rb +280 -0
- data/lib/bundler/installer/standalone.rb +113 -0
- data/lib/bundler/installer.rb +241 -0
- data/lib/bundler/lazy_specification.rb +270 -0
- data/lib/bundler/lockfile_generator.rb +119 -0
- data/lib/bundler/lockfile_parser.rb +328 -0
- data/lib/bundler/man/.document +1 -0
- data/lib/bundler/man/bundle-add.1 +79 -0
- data/lib/bundler/man/bundle-add.1.ronn +92 -0
- data/lib/bundler/man/bundle-binstubs.1 +30 -0
- data/lib/bundler/man/bundle-binstubs.1.ronn +42 -0
- data/lib/bundler/man/bundle-cache.1 +56 -0
- data/lib/bundler/man/bundle-cache.1.ronn +95 -0
- data/lib/bundler/man/bundle-check.1 +21 -0
- data/lib/bundler/man/bundle-check.1.ronn +26 -0
- data/lib/bundler/man/bundle-clean.1 +17 -0
- data/lib/bundler/man/bundle-clean.1.ronn +18 -0
- data/lib/bundler/man/bundle-config.1 +339 -0
- data/lib/bundler/man/bundle-config.1.ronn +455 -0
- data/lib/bundler/man/bundle-console.1 +33 -0
- data/lib/bundler/man/bundle-console.1.ronn +39 -0
- data/lib/bundler/man/bundle-doctor.1 +69 -0
- data/lib/bundler/man/bundle-doctor.1.ronn +77 -0
- data/lib/bundler/man/bundle-env.1 +9 -0
- data/lib/bundler/man/bundle-env.1.ronn +10 -0
- data/lib/bundler/man/bundle-exec.1 +104 -0
- data/lib/bundler/man/bundle-exec.1.ronn +150 -0
- data/lib/bundler/man/bundle-fund.1 +22 -0
- data/lib/bundler/man/bundle-fund.1.ronn +25 -0
- data/lib/bundler/man/bundle-gem.1 +107 -0
- data/lib/bundler/man/bundle-gem.1.ronn +150 -0
- data/lib/bundler/man/bundle-help.1 +9 -0
- data/lib/bundler/man/bundle-help.1.ronn +12 -0
- data/lib/bundler/man/bundle-info.1 +17 -0
- data/lib/bundler/man/bundle-info.1.ronn +21 -0
- data/lib/bundler/man/bundle-init.1 +20 -0
- data/lib/bundler/man/bundle-init.1.ronn +32 -0
- data/lib/bundler/man/bundle-install.1 +178 -0
- data/lib/bundler/man/bundle-install.1.ronn +314 -0
- data/lib/bundler/man/bundle-issue.1 +45 -0
- data/lib/bundler/man/bundle-issue.1.ronn +37 -0
- data/lib/bundler/man/bundle-licenses.1 +9 -0
- data/lib/bundler/man/bundle-licenses.1.ronn +10 -0
- data/lib/bundler/man/bundle-list.1 +40 -0
- data/lib/bundler/man/bundle-list.1.ronn +41 -0
- data/lib/bundler/man/bundle-lock.1 +75 -0
- data/lib/bundler/man/bundle-lock.1.ronn +115 -0
- data/lib/bundler/man/bundle-open.1 +32 -0
- data/lib/bundler/man/bundle-open.1.ronn +28 -0
- data/lib/bundler/man/bundle-outdated.1 +106 -0
- data/lib/bundler/man/bundle-outdated.1.ronn +117 -0
- data/lib/bundler/man/bundle-platform.1 +49 -0
- data/lib/bundler/man/bundle-platform.1.ronn +49 -0
- data/lib/bundler/man/bundle-plugin.1 +76 -0
- data/lib/bundler/man/bundle-plugin.1.ronn +84 -0
- data/lib/bundler/man/bundle-pristine.1 +23 -0
- data/lib/bundler/man/bundle-pristine.1.ronn +34 -0
- data/lib/bundler/man/bundle-remove.1 +15 -0
- data/lib/bundler/man/bundle-remove.1.ronn +16 -0
- data/lib/bundler/man/bundle-show.1 +16 -0
- data/lib/bundler/man/bundle-show.1.ronn +21 -0
- data/lib/bundler/man/bundle-update.1 +284 -0
- data/lib/bundler/man/bundle-update.1.ronn +367 -0
- data/lib/bundler/man/bundle-version.1 +22 -0
- data/lib/bundler/man/bundle-version.1.ronn +24 -0
- data/lib/bundler/man/bundle.1 +93 -0
- data/lib/bundler/man/bundle.1.ronn +107 -0
- data/lib/bundler/man/gemfile.5 +503 -0
- data/lib/bundler/man/gemfile.5.ronn +586 -0
- data/lib/bundler/man/index.txt +31 -0
- data/lib/bundler/match_metadata.rb +30 -0
- data/lib/bundler/match_platform.rb +42 -0
- data/lib/bundler/match_remote_metadata.rb +29 -0
- data/lib/bundler/materialization.rb +59 -0
- data/lib/bundler/mirror.rb +221 -0
- data/lib/bundler/plugin/api/source.rb +330 -0
- data/lib/bundler/plugin/api.rb +81 -0
- data/lib/bundler/plugin/dsl.rb +53 -0
- data/lib/bundler/plugin/events.rb +85 -0
- data/lib/bundler/plugin/index.rb +203 -0
- data/lib/bundler/plugin/installer/git.rb +34 -0
- data/lib/bundler/plugin/installer/path.rb +26 -0
- data/lib/bundler/plugin/installer/rubygems.rb +19 -0
- data/lib/bundler/plugin/installer.rb +123 -0
- data/lib/bundler/plugin/source_list.rb +31 -0
- data/lib/bundler/plugin/unloaded_source.rb +25 -0
- data/lib/bundler/plugin.rb +387 -0
- data/lib/bundler/process_lock.rb +20 -0
- data/lib/bundler/remote_specification.rb +126 -0
- data/lib/bundler/resolver/base.rb +127 -0
- data/lib/bundler/resolver/candidate.rb +85 -0
- data/lib/bundler/resolver/incompatibility.rb +15 -0
- data/lib/bundler/resolver/package.rb +95 -0
- data/lib/bundler/resolver/root.rb +25 -0
- data/lib/bundler/resolver/spec_group.rb +74 -0
- data/lib/bundler/resolver/strategy.rb +43 -0
- data/lib/bundler/resolver.rb +603 -0
- data/lib/bundler/retry.rb +92 -0
- data/lib/bundler/ruby_dsl.rb +67 -0
- data/lib/bundler/ruby_version.rb +135 -0
- data/lib/bundler/rubygems_ext.rb +503 -0
- data/lib/bundler/rubygems_gem_installer.rb +206 -0
- data/lib/bundler/rubygems_integration.rb +456 -0
- data/lib/bundler/runtime.rb +331 -0
- data/lib/bundler/safe_marshal.rb +31 -0
- data/lib/bundler/self_manager.rb +197 -0
- data/lib/bundler/settings/validator.rb +86 -0
- data/lib/bundler/settings.rb +585 -0
- data/lib/bundler/setup.rb +39 -0
- data/lib/bundler/shared_helpers.rb +392 -0
- data/lib/bundler/source/gemspec.rb +19 -0
- data/lib/bundler/source/git/git_proxy.rb +509 -0
- data/lib/bundler/source/git.rb +451 -0
- data/lib/bundler/source/metadata.rb +67 -0
- data/lib/bundler/source/path/installer.rb +53 -0
- data/lib/bundler/source/path.rb +256 -0
- data/lib/bundler/source/rubygems/remote.rb +86 -0
- data/lib/bundler/source/rubygems.rb +606 -0
- data/lib/bundler/source/rubygems_aggregate.rb +71 -0
- data/lib/bundler/source.rb +120 -0
- data/lib/bundler/source_list.rb +240 -0
- data/lib/bundler/source_map.rb +72 -0
- data/lib/bundler/spec_set.rb +390 -0
- data/lib/bundler/stub_specification.rb +147 -0
- data/lib/bundler/templates/.document +1 -0
- data/lib/bundler/templates/Executable +16 -0
- data/lib/bundler/templates/Executable.standalone +14 -0
- data/lib/bundler/templates/Gemfile +5 -0
- data/lib/bundler/templates/newgem/CHANGELOG.md.tt +5 -0
- data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +10 -0
- data/lib/bundler/templates/newgem/Cargo.toml.tt +13 -0
- data/lib/bundler/templates/newgem/Gemfile.tt +24 -0
- data/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
- data/lib/bundler/templates/newgem/README.md.tt +49 -0
- data/lib/bundler/templates/newgem/Rakefile.tt +72 -0
- data/lib/bundler/templates/newgem/bin/console.tt +11 -0
- data/lib/bundler/templates/newgem/bin/setup.tt +8 -0
- data/lib/bundler/templates/newgem/circleci/config.yml.tt +37 -0
- data/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
- data/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +22 -0
- data/lib/bundler/templates/newgem/ext/newgem/build.rs.tt +5 -0
- data/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
- data/lib/bundler/templates/newgem/ext/newgem/extconf-go.rb.tt +11 -0
- data/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
- data/lib/bundler/templates/newgem/ext/newgem/go.mod.tt +5 -0
- data/lib/bundler/templates/newgem/ext/newgem/newgem-go.c.tt +2 -0
- data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
- data/lib/bundler/templates/newgem/ext/newgem/newgem.go.tt +31 -0
- data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
- data/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +23 -0
- data/lib/bundler/templates/newgem/github/workflows/build-gems.yml.tt +69 -0
- data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +48 -0
- data/lib/bundler/templates/newgem/gitignore.tt +23 -0
- data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +27 -0
- data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +9 -0
- data/lib/bundler/templates/newgem/lib/newgem.rb.tt +15 -0
- data/lib/bundler/templates/newgem/newgem.gemspec.tt +58 -0
- data/lib/bundler/templates/newgem/rspec.tt +3 -0
- data/lib/bundler/templates/newgem/rubocop.yml.tt +8 -0
- data/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
- data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +19 -0
- data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +15 -0
- data/lib/bundler/templates/newgem/standard.yml.tt +3 -0
- data/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt +6 -0
- data/lib/bundler/templates/newgem/test/minitest/test_newgem.rb.tt +19 -0
- data/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt +15 -0
- data/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt +6 -0
- data/lib/bundler/ui/rg_proxy.rb +19 -0
- data/lib/bundler/ui/shell.rb +191 -0
- data/lib/bundler/ui/silent.rb +96 -0
- data/lib/bundler/ui.rb +9 -0
- data/lib/bundler/uri_credentials_filter.rb +43 -0
- data/lib/bundler/uri_normalizer.rb +23 -0
- data/lib/bundler/vendor/.document +1 -0
- data/lib/bundler/vendor/connection_pool/LICENSE +20 -0
- data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +227 -0
- data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +3 -0
- data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +56 -0
- data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +230 -0
- data/lib/bundler/vendor/fileutils/COPYING +56 -0
- data/lib/bundler/vendor/fileutils/lib/fileutils.rb +2701 -0
- data/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +41 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +65 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +80 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1153 -0
- data/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +169 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +61 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/strategy.rb +42 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +423 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +236 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
- data/lib/bundler/vendor/securerandom/COPYING +56 -0
- data/lib/bundler/vendor/securerandom/lib/securerandom.rb +102 -0
- data/lib/bundler/vendor/thor/LICENSE.md +20 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +105 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +61 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +108 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +143 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +407 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +130 -0
- data/lib/bundler/vendor/thor/lib/thor/actions.rb +340 -0
- data/lib/bundler/vendor/thor/lib/thor/base.rb +825 -0
- data/lib/bundler/vendor/thor/lib/thor/command.rb +151 -0
- data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +107 -0
- data/lib/bundler/vendor/thor/lib/thor/error.rb +106 -0
- data/lib/bundler/vendor/thor/lib/thor/group.rb +292 -0
- data/lib/bundler/vendor/thor/lib/thor/invocation.rb +178 -0
- data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +37 -0
- data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
- data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
- data/lib/bundler/vendor/thor/lib/thor/nested_context.rb +29 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +86 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +195 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +178 -0
- data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +294 -0
- data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
- data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +72 -0
- data/lib/bundler/vendor/thor/lib/thor/runner.rb +335 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +384 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +112 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb +29 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +81 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb +118 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb +42 -0
- data/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb +38 -0
- data/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
- data/lib/bundler/vendor/thor/lib/thor/util.rb +285 -0
- data/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
- data/lib/bundler/vendor/thor/lib/thor.rb +674 -0
- data/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
- data/lib/bundler/vendor/tsort/lib/tsort.rb +455 -0
- data/lib/bundler/vendor/uri/COPYING +56 -0
- data/lib/bundler/vendor/uri/lib/uri/common.rb +922 -0
- data/lib/bundler/vendor/uri/lib/uri/file.rb +100 -0
- data/lib/bundler/vendor/uri/lib/uri/ftp.rb +267 -0
- data/lib/bundler/vendor/uri/lib/uri/generic.rb +1592 -0
- data/lib/bundler/vendor/uri/lib/uri/http.rb +137 -0
- data/lib/bundler/vendor/uri/lib/uri/https.rb +23 -0
- data/lib/bundler/vendor/uri/lib/uri/ldap.rb +261 -0
- data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +22 -0
- data/lib/bundler/vendor/uri/lib/uri/mailto.rb +293 -0
- data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +547 -0
- data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +206 -0
- data/lib/bundler/vendor/uri/lib/uri/version.rb +6 -0
- data/lib/bundler/vendor/uri/lib/uri/ws.rb +83 -0
- data/lib/bundler/vendor/uri/lib/uri/wss.rb +23 -0
- data/lib/bundler/vendor/uri/lib/uri.rb +104 -0
- data/lib/bundler/vendored_fileutils.rb +4 -0
- data/lib/bundler/vendored_net_http.rb +23 -0
- data/lib/bundler/vendored_persistent.rb +11 -0
- data/lib/bundler/vendored_pub_grub.rb +4 -0
- data/lib/bundler/vendored_securerandom.rb +12 -0
- data/lib/bundler/vendored_thor.rb +8 -0
- data/lib/bundler/vendored_timeout.rb +12 -0
- data/lib/bundler/vendored_tsort.rb +4 -0
- data/lib/bundler/vendored_uri.rb +21 -0
- data/lib/bundler/version.rb +21 -0
- data/lib/bundler/vlad.rb +4 -0
- data/lib/bundler/worker.rb +125 -0
- data/lib/bundler/yaml_serializer.rb +98 -0
- data/lib/bundler.rb +691 -0
- metadata +409 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
class Bundler::Thor
|
|
2
|
+
module Actions
|
|
3
|
+
# Creates an empty directory.
|
|
4
|
+
#
|
|
5
|
+
# ==== Parameters
|
|
6
|
+
# destination<String>:: the relative path to the destination root.
|
|
7
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
8
|
+
#
|
|
9
|
+
# ==== Examples
|
|
10
|
+
#
|
|
11
|
+
# empty_directory "doc"
|
|
12
|
+
#
|
|
13
|
+
def empty_directory(destination, config = {})
|
|
14
|
+
action EmptyDirectory.new(self, destination, config)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Class which holds create directory logic. This is the base class for
|
|
18
|
+
# other actions like create_file and directory.
|
|
19
|
+
#
|
|
20
|
+
# This implementation is based in Templater actions, created by Jonas Nicklas
|
|
21
|
+
# and Michael S. Klishin under MIT LICENSE.
|
|
22
|
+
#
|
|
23
|
+
class EmptyDirectory #:nodoc:
|
|
24
|
+
attr_reader :base, :destination, :given_destination, :relative_destination, :config
|
|
25
|
+
|
|
26
|
+
# Initializes given the source and destination.
|
|
27
|
+
#
|
|
28
|
+
# ==== Parameters
|
|
29
|
+
# base<Bundler::Thor::Base>:: A Bundler::Thor::Base instance
|
|
30
|
+
# source<String>:: Relative path to the source of this file
|
|
31
|
+
# destination<String>:: Relative path to the destination of this file
|
|
32
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
33
|
+
#
|
|
34
|
+
def initialize(base, destination, config = {})
|
|
35
|
+
@base = base
|
|
36
|
+
@config = {verbose: true}.merge(config)
|
|
37
|
+
self.destination = destination
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Checks if the destination file already exists.
|
|
41
|
+
#
|
|
42
|
+
# ==== Returns
|
|
43
|
+
# Boolean:: true if the file exists, false otherwise.
|
|
44
|
+
#
|
|
45
|
+
def exists?
|
|
46
|
+
::File.exist?(destination)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def invoke!
|
|
50
|
+
invoke_with_conflict_check do
|
|
51
|
+
require "fileutils"
|
|
52
|
+
::FileUtils.mkdir_p(destination)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def revoke!
|
|
57
|
+
say_status :remove, :red
|
|
58
|
+
require "fileutils"
|
|
59
|
+
::FileUtils.rm_rf(destination) if !pretend? && exists?
|
|
60
|
+
given_destination
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
protected
|
|
64
|
+
|
|
65
|
+
# Shortcut for pretend.
|
|
66
|
+
#
|
|
67
|
+
def pretend?
|
|
68
|
+
base.options[:pretend]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Sets the absolute destination value from a relative destination value.
|
|
72
|
+
# It also stores the given and relative destination. Let's suppose our
|
|
73
|
+
# script is being executed on "dest", it sets the destination root to
|
|
74
|
+
# "dest". The destination, given_destination and relative_destination
|
|
75
|
+
# are related in the following way:
|
|
76
|
+
#
|
|
77
|
+
# inside "bar" do
|
|
78
|
+
# empty_directory "baz"
|
|
79
|
+
# end
|
|
80
|
+
#
|
|
81
|
+
# destination #=> dest/bar/baz
|
|
82
|
+
# relative_destination #=> bar/baz
|
|
83
|
+
# given_destination #=> baz
|
|
84
|
+
#
|
|
85
|
+
def destination=(destination)
|
|
86
|
+
return unless destination
|
|
87
|
+
@given_destination = convert_encoded_instructions(destination.to_s)
|
|
88
|
+
@destination = ::File.expand_path(@given_destination, base.destination_root)
|
|
89
|
+
@relative_destination = base.relative_to_original_destination_root(@destination)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Filenames in the encoded form are converted. If you have a file:
|
|
93
|
+
#
|
|
94
|
+
# %file_name%.rb
|
|
95
|
+
#
|
|
96
|
+
# It calls #file_name from the base and replaces %-string with the
|
|
97
|
+
# return value (should be String) of #file_name:
|
|
98
|
+
#
|
|
99
|
+
# user.rb
|
|
100
|
+
#
|
|
101
|
+
# The method referenced can be either public or private.
|
|
102
|
+
#
|
|
103
|
+
def convert_encoded_instructions(filename)
|
|
104
|
+
filename.gsub(/%(.*?)%/) do |initial_string|
|
|
105
|
+
method = $1.strip
|
|
106
|
+
base.respond_to?(method, true) ? base.send(method) : initial_string
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Receives a hash of options and just execute the block if some
|
|
111
|
+
# conditions are met.
|
|
112
|
+
#
|
|
113
|
+
def invoke_with_conflict_check(&block)
|
|
114
|
+
if exists?
|
|
115
|
+
on_conflict_behavior(&block)
|
|
116
|
+
else
|
|
117
|
+
yield unless pretend?
|
|
118
|
+
say_status :create, :green
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
destination
|
|
122
|
+
rescue Errno::EISDIR, Errno::EEXIST
|
|
123
|
+
on_file_clash_behavior
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def on_file_clash_behavior
|
|
127
|
+
say_status :file_clash, :red
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# What to do when the destination file already exists.
|
|
131
|
+
#
|
|
132
|
+
def on_conflict_behavior
|
|
133
|
+
say_status :exist, :blue
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Shortcut to say_status shell method.
|
|
137
|
+
#
|
|
138
|
+
def say_status(status, color)
|
|
139
|
+
base.shell.say_status status, relative_destination, color if config[:verbose]
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
|
|
3
|
+
class Bundler::Thor
|
|
4
|
+
module Actions
|
|
5
|
+
# Copies the file from the relative source to the relative destination. If
|
|
6
|
+
# the destination is not given it's assumed to be equal to the source.
|
|
7
|
+
#
|
|
8
|
+
# ==== Parameters
|
|
9
|
+
# source<String>:: the relative path to the source root.
|
|
10
|
+
# destination<String>:: the relative path to the destination root.
|
|
11
|
+
# config<Hash>:: give :verbose => false to not log the status, and
|
|
12
|
+
# :mode => :preserve, to preserve the file mode from the source.
|
|
13
|
+
#
|
|
14
|
+
# ==== Examples
|
|
15
|
+
#
|
|
16
|
+
# copy_file "README", "doc/README"
|
|
17
|
+
#
|
|
18
|
+
# copy_file "doc/README"
|
|
19
|
+
#
|
|
20
|
+
def copy_file(source, *args, &block)
|
|
21
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
22
|
+
destination = args.first || source
|
|
23
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
|
24
|
+
|
|
25
|
+
resulting_destination = create_file destination, nil, config do
|
|
26
|
+
content = File.binread(source)
|
|
27
|
+
content = yield(content) if block
|
|
28
|
+
content
|
|
29
|
+
end
|
|
30
|
+
if config[:mode] == :preserve
|
|
31
|
+
mode = File.stat(source).mode
|
|
32
|
+
chmod(resulting_destination, mode, config)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Links the file from the relative source to the relative destination. If
|
|
37
|
+
# the destination is not given it's assumed to be equal to the source.
|
|
38
|
+
#
|
|
39
|
+
# ==== Parameters
|
|
40
|
+
# source<String>:: the relative path to the source root.
|
|
41
|
+
# destination<String>:: the relative path to the destination root.
|
|
42
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
43
|
+
#
|
|
44
|
+
# ==== Examples
|
|
45
|
+
#
|
|
46
|
+
# link_file "README", "doc/README"
|
|
47
|
+
#
|
|
48
|
+
# link_file "doc/README"
|
|
49
|
+
#
|
|
50
|
+
def link_file(source, *args)
|
|
51
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
52
|
+
destination = args.first || source
|
|
53
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
|
54
|
+
|
|
55
|
+
create_link destination, source, config
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Gets the content at the given address and places it at the given relative
|
|
59
|
+
# destination. If a block is given instead of destination, the content of
|
|
60
|
+
# the url is yielded and used as location.
|
|
61
|
+
#
|
|
62
|
+
# +get+ relies on open-uri, so passing application user input would provide
|
|
63
|
+
# a command injection attack vector.
|
|
64
|
+
#
|
|
65
|
+
# ==== Parameters
|
|
66
|
+
# source<String>:: the address of the given content.
|
|
67
|
+
# destination<String>:: the relative path to the destination root.
|
|
68
|
+
# config<Hash>:: give :verbose => false to not log the status, and
|
|
69
|
+
# :http_headers => <Hash> to add headers to an http request.
|
|
70
|
+
#
|
|
71
|
+
# ==== Examples
|
|
72
|
+
#
|
|
73
|
+
# get "http://gist.github.com/103208", "doc/README"
|
|
74
|
+
#
|
|
75
|
+
# get "http://gist.github.com/103208", "doc/README", :http_headers => {"Content-Type" => "application/json"}
|
|
76
|
+
#
|
|
77
|
+
# get "http://gist.github.com/103208" do |content|
|
|
78
|
+
# content.split("\n").first
|
|
79
|
+
# end
|
|
80
|
+
#
|
|
81
|
+
def get(source, *args, &block)
|
|
82
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
83
|
+
destination = args.first
|
|
84
|
+
|
|
85
|
+
render = if source =~ %r{^https?\://}
|
|
86
|
+
require "open-uri"
|
|
87
|
+
URI.send(:open, source, config.fetch(:http_headers, {})) { |input| input.binmode.read }
|
|
88
|
+
else
|
|
89
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
|
90
|
+
File.open(source) { |input| input.binmode.read }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
destination ||= if block_given?
|
|
94
|
+
block.arity == 1 ? yield(render) : yield
|
|
95
|
+
else
|
|
96
|
+
File.basename(source)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
create_file destination, render, config
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Gets an ERB template at the relative source, executes it and makes a copy
|
|
103
|
+
# at the relative destination. If the destination is not given it's assumed
|
|
104
|
+
# to be equal to the source removing .tt from the filename.
|
|
105
|
+
#
|
|
106
|
+
# ==== Parameters
|
|
107
|
+
# source<String>:: the relative path to the source root.
|
|
108
|
+
# destination<String>:: the relative path to the destination root.
|
|
109
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
110
|
+
#
|
|
111
|
+
# ==== Examples
|
|
112
|
+
#
|
|
113
|
+
# template "README", "doc/README"
|
|
114
|
+
#
|
|
115
|
+
# template "doc/README"
|
|
116
|
+
#
|
|
117
|
+
def template(source, *args, &block)
|
|
118
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
119
|
+
destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/, "")
|
|
120
|
+
|
|
121
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
|
122
|
+
context = config.delete(:context) || instance_eval("binding")
|
|
123
|
+
|
|
124
|
+
create_file destination, nil, config do
|
|
125
|
+
capturable_erb = CapturableERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer")
|
|
126
|
+
content = capturable_erb.tap do |erb|
|
|
127
|
+
erb.filename = source
|
|
128
|
+
end.result(context)
|
|
129
|
+
content = yield(content) if block
|
|
130
|
+
content
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Changes the mode of the given file or directory.
|
|
135
|
+
#
|
|
136
|
+
# ==== Parameters
|
|
137
|
+
# mode<Integer>:: the file mode
|
|
138
|
+
# path<String>:: the name of the file to change mode
|
|
139
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
140
|
+
#
|
|
141
|
+
# ==== Example
|
|
142
|
+
#
|
|
143
|
+
# chmod "script/server", 0755
|
|
144
|
+
#
|
|
145
|
+
def chmod(path, mode, config = {})
|
|
146
|
+
return unless behavior == :invoke
|
|
147
|
+
path = File.expand_path(path, destination_root)
|
|
148
|
+
say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
|
149
|
+
unless options[:pretend]
|
|
150
|
+
require "fileutils"
|
|
151
|
+
FileUtils.chmod_R(mode, path)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Prepend text to a file. Since it depends on insert_into_file, it's reversible.
|
|
156
|
+
#
|
|
157
|
+
# ==== Parameters
|
|
158
|
+
# path<String>:: path of the file to be changed
|
|
159
|
+
# data<String>:: the data to prepend to the file, can be also given as a block.
|
|
160
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
161
|
+
#
|
|
162
|
+
# ==== Example
|
|
163
|
+
#
|
|
164
|
+
# prepend_to_file 'config/environments/test.rb', 'config.gem "rspec"'
|
|
165
|
+
#
|
|
166
|
+
# prepend_to_file 'config/environments/test.rb' do
|
|
167
|
+
# 'config.gem "rspec"'
|
|
168
|
+
# end
|
|
169
|
+
#
|
|
170
|
+
def prepend_to_file(path, *args, &block)
|
|
171
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
172
|
+
config[:after] = /\A/
|
|
173
|
+
insert_into_file(path, *(args << config), &block)
|
|
174
|
+
end
|
|
175
|
+
alias_method :prepend_file, :prepend_to_file
|
|
176
|
+
|
|
177
|
+
# Append text to a file. Since it depends on insert_into_file, it's reversible.
|
|
178
|
+
#
|
|
179
|
+
# ==== Parameters
|
|
180
|
+
# path<String>:: path of the file to be changed
|
|
181
|
+
# data<String>:: the data to append to the file, can be also given as a block.
|
|
182
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
183
|
+
#
|
|
184
|
+
# ==== Example
|
|
185
|
+
#
|
|
186
|
+
# append_to_file 'config/environments/test.rb', 'config.gem "rspec"'
|
|
187
|
+
#
|
|
188
|
+
# append_to_file 'config/environments/test.rb' do
|
|
189
|
+
# 'config.gem "rspec"'
|
|
190
|
+
# end
|
|
191
|
+
#
|
|
192
|
+
def append_to_file(path, *args, &block)
|
|
193
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
194
|
+
config[:before] = /\z/
|
|
195
|
+
insert_into_file(path, *(args << config), &block)
|
|
196
|
+
end
|
|
197
|
+
alias_method :append_file, :append_to_file
|
|
198
|
+
|
|
199
|
+
# Injects text right after the class definition. Since it depends on
|
|
200
|
+
# insert_into_file, it's reversible.
|
|
201
|
+
#
|
|
202
|
+
# ==== Parameters
|
|
203
|
+
# path<String>:: path of the file to be changed
|
|
204
|
+
# klass<String|Class>:: the class to be manipulated
|
|
205
|
+
# data<String>:: the data to append to the class, can be also given as a block.
|
|
206
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
207
|
+
#
|
|
208
|
+
# ==== Examples
|
|
209
|
+
#
|
|
210
|
+
# inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " filter_parameter :password\n"
|
|
211
|
+
#
|
|
212
|
+
# inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
|
|
213
|
+
# " filter_parameter :password\n"
|
|
214
|
+
# end
|
|
215
|
+
#
|
|
216
|
+
def inject_into_class(path, klass, *args, &block)
|
|
217
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
218
|
+
config[:after] = /class #{klass}\n|class #{klass} .*\n/
|
|
219
|
+
insert_into_file(path, *(args << config), &block)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Injects text right after the module definition. Since it depends on
|
|
223
|
+
# insert_into_file, it's reversible.
|
|
224
|
+
#
|
|
225
|
+
# ==== Parameters
|
|
226
|
+
# path<String>:: path of the file to be changed
|
|
227
|
+
# module_name<String|Class>:: the module to be manipulated
|
|
228
|
+
# data<String>:: the data to append to the class, can be also given as a block.
|
|
229
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
230
|
+
#
|
|
231
|
+
# ==== Examples
|
|
232
|
+
#
|
|
233
|
+
# inject_into_module "app/helpers/application_helper.rb", "ApplicationHelper", " def help; 'help'; end\n"
|
|
234
|
+
#
|
|
235
|
+
# inject_into_module "app/helpers/application_helper.rb", "ApplicationHelper" do
|
|
236
|
+
# " def help; 'help'; end\n"
|
|
237
|
+
# end
|
|
238
|
+
#
|
|
239
|
+
def inject_into_module(path, module_name, *args, &block)
|
|
240
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
241
|
+
config[:after] = /module #{module_name}\n|module #{module_name} .*\n/
|
|
242
|
+
insert_into_file(path, *(args << config), &block)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# Run a regular expression replacement on a file, raising an error if the
|
|
246
|
+
# contents of the file are not changed.
|
|
247
|
+
#
|
|
248
|
+
# ==== Parameters
|
|
249
|
+
# path<String>:: path of the file to be changed
|
|
250
|
+
# flag<Regexp|String>:: the regexp or string to be replaced
|
|
251
|
+
# replacement<String>:: the replacement, can be also given as a block
|
|
252
|
+
# config<Hash>:: give :verbose => false to not log the status, and
|
|
253
|
+
# :force => true, to force the replacement regardless of runner behavior.
|
|
254
|
+
#
|
|
255
|
+
# ==== Example
|
|
256
|
+
#
|
|
257
|
+
# gsub_file! 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
|
|
258
|
+
#
|
|
259
|
+
# gsub_file! 'README', /rake/, :green do |match|
|
|
260
|
+
# match << " no more. Use thor!"
|
|
261
|
+
# end
|
|
262
|
+
#
|
|
263
|
+
def gsub_file!(path, flag, *args, &block)
|
|
264
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
265
|
+
|
|
266
|
+
return unless behavior == :invoke || config.fetch(:force, false)
|
|
267
|
+
|
|
268
|
+
path = File.expand_path(path, destination_root)
|
|
269
|
+
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
|
270
|
+
|
|
271
|
+
actually_gsub_file(path, flag, args, true, &block) unless options[:pretend]
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# Run a regular expression replacement on a file.
|
|
275
|
+
#
|
|
276
|
+
# ==== Parameters
|
|
277
|
+
# path<String>:: path of the file to be changed
|
|
278
|
+
# flag<Regexp|String>:: the regexp or string to be replaced
|
|
279
|
+
# replacement<String>:: the replacement, can be also given as a block
|
|
280
|
+
# config<Hash>:: give :verbose => false to not log the status, and
|
|
281
|
+
# :force => true, to force the replacement regardless of runner behavior.
|
|
282
|
+
#
|
|
283
|
+
# ==== Example
|
|
284
|
+
#
|
|
285
|
+
# gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
|
|
286
|
+
#
|
|
287
|
+
# gsub_file 'README', /rake/, :green do |match|
|
|
288
|
+
# match << " no more. Use thor!"
|
|
289
|
+
# end
|
|
290
|
+
#
|
|
291
|
+
def gsub_file(path, flag, *args, &block)
|
|
292
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
293
|
+
|
|
294
|
+
return unless behavior == :invoke || config.fetch(:force, false)
|
|
295
|
+
|
|
296
|
+
path = File.expand_path(path, destination_root)
|
|
297
|
+
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
|
298
|
+
|
|
299
|
+
actually_gsub_file(path, flag, args, false, &block) unless options[:pretend]
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Uncomment all lines matching a given regex. Preserves indentation before
|
|
303
|
+
# the comment hash and removes the hash and any immediate following space.
|
|
304
|
+
#
|
|
305
|
+
# ==== Parameters
|
|
306
|
+
# path<String>:: path of the file to be changed
|
|
307
|
+
# flag<Regexp|String>:: the regexp or string used to decide which lines to uncomment
|
|
308
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
309
|
+
#
|
|
310
|
+
# ==== Example
|
|
311
|
+
#
|
|
312
|
+
# uncomment_lines 'config/initializers/session_store.rb', /active_record/
|
|
313
|
+
#
|
|
314
|
+
def uncomment_lines(path, flag, *args)
|
|
315
|
+
flag = flag.respond_to?(:source) ? flag.source : flag
|
|
316
|
+
|
|
317
|
+
gsub_file(path, /^(\s*)#[[:blank:]]?(.*#{flag})/, '\1\2', *args)
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Comment all lines matching a given regex. It will leave the space
|
|
321
|
+
# which existed before the beginning of the line in tact and will insert
|
|
322
|
+
# a single space after the comment hash.
|
|
323
|
+
#
|
|
324
|
+
# ==== Parameters
|
|
325
|
+
# path<String>:: path of the file to be changed
|
|
326
|
+
# flag<Regexp|String>:: the regexp or string used to decide which lines to comment
|
|
327
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
328
|
+
#
|
|
329
|
+
# ==== Example
|
|
330
|
+
#
|
|
331
|
+
# comment_lines 'config/initializers/session_store.rb', /cookie_store/
|
|
332
|
+
#
|
|
333
|
+
def comment_lines(path, flag, *args)
|
|
334
|
+
flag = flag.respond_to?(:source) ? flag.source : flag
|
|
335
|
+
|
|
336
|
+
gsub_file(path, /^(\s*)([^#\n]*#{flag})/, '\1# \2', *args)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# Removes a file at the given location.
|
|
340
|
+
#
|
|
341
|
+
# ==== Parameters
|
|
342
|
+
# path<String>:: path of the file to be changed
|
|
343
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
|
344
|
+
#
|
|
345
|
+
# ==== Example
|
|
346
|
+
#
|
|
347
|
+
# remove_file 'README'
|
|
348
|
+
# remove_file 'app/controllers/application_controller.rb'
|
|
349
|
+
#
|
|
350
|
+
def remove_file(path, config = {})
|
|
351
|
+
return unless behavior == :invoke
|
|
352
|
+
path = File.expand_path(path, destination_root)
|
|
353
|
+
|
|
354
|
+
say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
|
|
355
|
+
if !options[:pretend] && (File.exist?(path) || File.symlink?(path))
|
|
356
|
+
require "fileutils"
|
|
357
|
+
::FileUtils.rm_rf(path)
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
alias_method :remove_dir, :remove_file
|
|
361
|
+
|
|
362
|
+
attr_accessor :output_buffer
|
|
363
|
+
private :output_buffer, :output_buffer=
|
|
364
|
+
|
|
365
|
+
private
|
|
366
|
+
|
|
367
|
+
def concat(string)
|
|
368
|
+
@output_buffer.concat(string)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
def capture(*args)
|
|
372
|
+
with_output_buffer { yield(*args) }
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def with_output_buffer(buf = "".dup) #:nodoc:
|
|
376
|
+
raise ArgumentError, "Buffer cannot be a frozen object" if buf.frozen?
|
|
377
|
+
old_buffer = output_buffer
|
|
378
|
+
self.output_buffer = buf
|
|
379
|
+
yield
|
|
380
|
+
output_buffer
|
|
381
|
+
ensure
|
|
382
|
+
self.output_buffer = old_buffer
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
def actually_gsub_file(path, flag, args, error_on_no_change, &block)
|
|
386
|
+
content = File.binread(path)
|
|
387
|
+
success = content.gsub!(flag, *args, &block)
|
|
388
|
+
|
|
389
|
+
if success.nil? && error_on_no_change
|
|
390
|
+
raise Bundler::Thor::Error, "The content of #{path} did not change"
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
File.open(path, "wb") { |file| file.write(content) }
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
# Bundler::Thor::Actions#capture depends on what kind of buffer is used in ERB.
|
|
397
|
+
# Thus CapturableERB fixes ERB to use String buffer.
|
|
398
|
+
class CapturableERB < ERB
|
|
399
|
+
def set_eoutvar(compiler, eoutvar = "_erbout")
|
|
400
|
+
compiler.put_cmd = "#{eoutvar}.concat"
|
|
401
|
+
compiler.insert_cmd = "#{eoutvar}.concat"
|
|
402
|
+
compiler.pre_cmd = ["#{eoutvar} = ''.dup"]
|
|
403
|
+
compiler.post_cmd = [eoutvar]
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
require_relative "empty_directory"
|
|
2
|
+
|
|
3
|
+
class Bundler::Thor
|
|
4
|
+
module Actions
|
|
5
|
+
# Injects the given content into a file. Different from gsub_file, this
|
|
6
|
+
# method is reversible.
|
|
7
|
+
#
|
|
8
|
+
# ==== Parameters
|
|
9
|
+
# destination<String>:: Relative path to the destination root
|
|
10
|
+
# data<String>:: Data to add to the file. Can be given as a block.
|
|
11
|
+
# config<Hash>:: give :verbose => false to not log the status and the flag
|
|
12
|
+
# for injection (:after or :before) or :force => true for
|
|
13
|
+
# insert two or more times the same content.
|
|
14
|
+
#
|
|
15
|
+
# ==== Examples
|
|
16
|
+
#
|
|
17
|
+
# insert_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n"
|
|
18
|
+
#
|
|
19
|
+
# insert_into_file "config/environment.rb", :after => "Rails::Initializer.run do |config|\n" do
|
|
20
|
+
# gems = ask "Which gems would you like to add?"
|
|
21
|
+
# gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n")
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
WARNINGS = {unchanged_no_flag: "File unchanged! Either the supplied flag value not found or the content has already been inserted!"}
|
|
25
|
+
|
|
26
|
+
def insert_into_file(destination, *args, &block)
|
|
27
|
+
data = block_given? ? block : args.shift
|
|
28
|
+
|
|
29
|
+
config = args.shift || {}
|
|
30
|
+
config[:after] = /\z/ unless config.key?(:before) || config.key?(:after)
|
|
31
|
+
|
|
32
|
+
action InjectIntoFile.new(self, destination, data, config)
|
|
33
|
+
end
|
|
34
|
+
alias_method :inject_into_file, :insert_into_file
|
|
35
|
+
|
|
36
|
+
class InjectIntoFile < EmptyDirectory #:nodoc:
|
|
37
|
+
attr_reader :replacement, :flag, :behavior
|
|
38
|
+
|
|
39
|
+
def initialize(base, destination, data, config)
|
|
40
|
+
super(base, destination, {verbose: true}.merge(config))
|
|
41
|
+
|
|
42
|
+
@behavior, @flag = if @config.key?(:after)
|
|
43
|
+
[:after, @config.delete(:after)]
|
|
44
|
+
else
|
|
45
|
+
[:before, @config.delete(:before)]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
@replacement = data.is_a?(Proc) ? data.call : data
|
|
49
|
+
@flag = Regexp.escape(@flag) unless @flag.is_a?(Regexp)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def invoke!
|
|
53
|
+
content = if @behavior == :after
|
|
54
|
+
'\0' + replacement
|
|
55
|
+
else
|
|
56
|
+
replacement + '\0'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if exists?
|
|
60
|
+
if replace!(/#{flag}/, content, config[:force])
|
|
61
|
+
say_status(:invoke)
|
|
62
|
+
elsif replacement_present?
|
|
63
|
+
say_status(:unchanged, color: :blue)
|
|
64
|
+
else
|
|
65
|
+
say_status(:unchanged, warning: WARNINGS[:unchanged_no_flag], color: :red)
|
|
66
|
+
end
|
|
67
|
+
else
|
|
68
|
+
unless pretend?
|
|
69
|
+
raise Bundler::Thor::Error, "The file #{ destination } does not appear to exist"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def revoke!
|
|
75
|
+
say_status :revoke
|
|
76
|
+
|
|
77
|
+
regexp = if @behavior == :after
|
|
78
|
+
content = '\1\2'
|
|
79
|
+
/(#{flag})(.*)(#{Regexp.escape(replacement)})/m
|
|
80
|
+
else
|
|
81
|
+
content = '\2\3'
|
|
82
|
+
/(#{Regexp.escape(replacement)})(.*)(#{flag})/m
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
replace!(regexp, content, true)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
protected
|
|
89
|
+
|
|
90
|
+
def say_status(behavior, warning: nil, color: nil)
|
|
91
|
+
status = if behavior == :invoke
|
|
92
|
+
if flag == /\A/
|
|
93
|
+
:prepend
|
|
94
|
+
elsif flag == /\z/
|
|
95
|
+
:append
|
|
96
|
+
else
|
|
97
|
+
:insert
|
|
98
|
+
end
|
|
99
|
+
elsif warning
|
|
100
|
+
warning
|
|
101
|
+
elsif behavior == :unchanged
|
|
102
|
+
:unchanged
|
|
103
|
+
else
|
|
104
|
+
:subtract
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
super(status, (color || config[:verbose]))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def content
|
|
111
|
+
@content ||= File.read(destination)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def replacement_present?
|
|
115
|
+
content.include?(replacement)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Adds the content to the file.
|
|
119
|
+
#
|
|
120
|
+
def replace!(regexp, string, force)
|
|
121
|
+
if force || !replacement_present?
|
|
122
|
+
success = content.gsub!(regexp, string)
|
|
123
|
+
|
|
124
|
+
File.open(destination, "wb") { |file| file.write(content) } unless pretend?
|
|
125
|
+
success
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|