README.md in gem_bench-2.0.0 vs README.md in gem_bench-2.0.1

- old
+ new

@@ -1,52 +1,153 @@ # GemBench +<div id="badges"> + +<div align="center"> + +[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) +[![Version](https://img.shields.io/gem/v/gem_bench.svg)](https://rubygems.org/gems/gem_bench) +[![Downloads Today](https://img.shields.io/gem/rd/gem_bench.svg)](https://github.com/pboling/gem_bench) +[![Depfu](https://badges.depfu.com/badges/865e7bb1d0d3eb3ba807fca7344e22d1/overview.svg)](https://depfu.com/github/pboling/gem_bench?project_id=2688) +[![Test Coverage](https://api.codeclimate.com/v1/badges/80787f126e7a486b19af/test_coverage)](https://codeclimate.com/github/pboling/gem_bench/test_coverage) +[![Maintainability](https://api.codeclimate.com/v1/badges/80787f126e7a486b19af/maintainability)](https://codeclimate.com/github/pboling/gem_bench/maintainability) +[![CI Supported Build][🚎s-wfi]][🚎s-wf] +[![CI Unsupported Build][🚎us-wfi]][🚎us-wf] +[![CI Style Build][🚎st-wfi]][🚎st-wf] +[![CI Coverage Build][🚎cov-wfi]][🚎cov-wf] +[![CI Heads Build][🚎hd-wfi]][🚎hd-wf] + +[🚎s-wf]: https://github.com/pboling/gem_bench/actions/workflows/supported.yml +[🚎s-wfi]: https://github.com/pboling/gem_bench/actions/workflows/supported.yml/badge.svg +[🚎us-wf]: https://github.com/pboling/gem_bench/actions/workflows/unsupported.yml +[🚎us-wfi]: https://github.com/pboling/gem_bench/actions/workflows/unsupported.yml/badge.svg +[🚎st-wf]: https://github.com/pboling/gem_bench/actions/workflows/style.yml +[🚎st-wfi]: https://github.com/pboling/gem_bench/actions/workflows/style.yml/badge.svg +[🚎cov-wf]: https://github.com/pboling/gem_bench/actions/workflows/coverage.yml +[🚎cov-wfi]: https://github.com/pboling/gem_bench/actions/workflows/coverage.yml/badge.svg +[🚎hd-wf]: https://github.com/pboling/gem_bench/actions/workflows/heads.yml +[🚎hd-wfi]: https://github.com/pboling/gem_bench/actions/workflows/heads.yml/badge.svg + +</div> + +----- + +<div align="center"> + +[![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] +[![Sponsor Me on Github][🖇sponsor-img]][🖇sponsor] +[![Polar Shield][🖇polar-img]][🖇polar] +[![Donate to my FLOSS or refugee efforts at ko-fi.com][🖇kofi-img]][🖇kofi] +[![Donate to my FLOSS or refugee efforts using Patreon][🖇patreon-img]][🖇patreon] + +[⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay +[⛳liberapay]: https://liberapay.com/pboling/donate +[🖇sponsor-img]: https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github +[🖇sponsor]: https://github.com/sponsors/pboling +[🖇polar-img]: https://polar.sh/embed/seeks-funding-shield.svg?org=pboling +[🖇polar]: https://polar.sh/pboling +[🖇kofi-img]: https://img.shields.io/badge/buy%20me%20coffee-donate-yellow.svg +[🖇kofi]: https://ko-fi.com/O5O86SNP4 +[🖇patreon-img]: https://img.shields.io/badge/patreon-donate-yellow.svg +[🖇patreon]: https://patreon.com/galtzo + +<span class="badge-buymealatte"> +<a href="https://www.buymeacoffee.com/pboling"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a latte&emoji=&slug=pboling&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" /></a> +</span> + +</div> +</div> + +Scene: You are a spectator at a game of Ruby Sports Gem Ball. + +Gem wearing jersey namespace **#23**: + +> "Put me in coach!" + +Other Gem, also wearing jersey namespace **#23**: + +> "Put me in coach!" + +Coach: + +> ❨╯°□°❩╯︵┻━┻ fine, but one of you change your jersey first! + +## What's it do? + `gem_bench` is for static Gemfile and installed gem library source code analysis. -`gem_bench` can also be used to trim down app load times by keeping your worst players on the bench. +`gem_bench` can be used to re-namespace a gem at run-time so that you can run simultaneously: -Gem: "Put me in coach!" -You: ❨╯°□°❩╯︵┻━┻ +- two versions of the same library, or +- two different things that happen to have a namespace collision, +for benchmarking or other purposes. + +`gem_bench` can also be used to trim down app load times by keeping your worst players on the bench. + | Project | GemBench | |------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | gem name | [gem_bench](https://rubygems.org/gems/gem_bench) | -| license | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) | -| download rank | [![Downloads Today](https://img.shields.io/gem/rd/gem_bench.svg)](https://github.com/pboling/gem_bench) | -| version | [![Version](https://img.shields.io/gem/v/gem_bench.svg)](https://rubygems.org/gems/gem_bench) | -| dependencies | [![Depfu](https://badges.depfu.com/badges/865e7bb1d0d3eb3ba807fca7344e22d1/overview.svg)](https://depfu.com/github/pboling/gem_bench?project_id=5613) | -| continuous integration | [![Current][🚎cwfi]][🚎cwf] [![Heads][🖐hwfi]][🖐hwf] [![Style][🧮swfi]][🧮swf] [![Coverage][📗cov-wfi]][📗cov-wf] | -| test coverage | [![Test Coverage](https://api.codeclimate.com/v1/badges/80787f126e7a486b19af/test_coverage)](https://codeclimate.com/github/pboling/gem_bench/test_coverage) | -| maintainability | [![Maintainability](https://api.codeclimate.com/v1/badges/80787f126e7a486b19af/maintainability)](https://codeclimate.com/github/pboling/gem_bench/maintainability) | | code triage | [![Open Source Helpers](https://www.codetriage.com/pboling/gem_bench/badges/users.svg)](https://www.codetriage.com/pboling/gem_bench) | | homepage | [on Github.com][homepage] | | documentation | [on Rdoc.info][documentation] | | live chat | [![Join the chat][🏘chati]][🏘chat] | | expert support | [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) | -| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌏](https://about.me/peter.boling), [👼](https://angel.co/peter-boling), [![Tweet Peter](https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow)](http://twitter.com/galtzo) | +| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌏](https://about.me/peter.boling) [👼](https://angel.co/peter-boling) [![Tweet Peter](https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow)](http://twitter.com/galtzo) | -[🚎cwf]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/current.yml -[🚎cwfi]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/current.yml/badge.svg -[🖐hwf]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/heads.yml -[🖐hwfi]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/heads.yml/badge.svg -[🧮swf]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/style.yml -[🧮swfi]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/style.yml/badge.svg -[📗cov-wf]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/coverage.yml -[📗cov-wfi]: https://github.com/rubocop-lts/rubocop-lts/actions/workflows/coverage.yml/badge.svg [🏘chat]: https://matrix.to/#/%23pboling_gem_bench:gitter.im [🏘chati]: https://badges.gitter.im/Join%20Chat.svg +### New for 2.0.1 - `GemBench::Jersey` + +Allows you to re-namespace any gem. +You can, for example, benchmark a gem against another version of itself. + +The gem `alt_memery` uses a namespace, `Memery`, that does not match the gem name. + +```ruby +require "gem_bench/jersey" + +jersey = GemBench::Jersey.new( + gem_name: "alt_memery", + trades: {"Memery" => "AltMemery"}, + metadata: { # optional, mostly used for benchmarking report output + something: "a value here", + something_else: :obviously, + }, +) +jersey.doff_and_don +# The re-namespaced constant is now available! +AltMemery # => AltMemery +jersey.as_klass # => AltMemery + +# The original, unmodified, gem is still there! +require "alt_memery" + +Memery # => Memery +# So you can use both! +``` + +NOTE: It is not required by default, so you do need to require the Jersey if you want to use it! + +```ruby +require "gem_bench/jersey" +``` + +For a real example, see: https://github.com/panorama-ed/memo_wise/pull/339 + ### New for 2.0.0 - Dropped Support for Ruby 2.0, 2.1, 2.2 --- Required Ruby is now 2.3+ +- Required Ruby is now 2.3+ - `VERSION` is now namespaced at `GemBench::Version::VERSION` and is enhanced by `version_gem`. ### New for 1.0.2 - Gemfile specs Version constraints are important. Give the Gemfile some love in your CI build Create a `spec/gemfile_spec.rb` like: + ```ruby Rspec.describe("Gemfile") do it("has version constraint on every gem") do requirements = GemBench::StrictVersionRequirement.new({verbose: false}) expect(requirements.list_missing_version_constraints).to(eq([])) @@ -74,13 +175,18 @@ ### New for 1.0.0 - Find WAT Dragons in 3rd party source code Search the Ruby source code of all the gems loaded by your Gemfile for a specified regex, to find out which gems have wat DRAGONS. -Gem: "I have no wat DRAGONS!" -You: ❨╯°□°❩╯︵┻━┻ +Gem: +> "I have no wat DRAGONS!"` + +You: + +> ❨╯°□°❩╯︵┻━┻ Yes you do! + ``` >> puts GemBench.find(look_for_regex: /wat/).starters.map {|gem| "#{gem.name} has wat DRAGONS at #{gem.stats}" }.join("\n") [GemBench] Will search for gems in ["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@global/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@foss/bundler/gems"] [GemBench] Detected 11 loaded gems + 2 loaded gems which GemBench is configured to ignore. byebug has wat DRAGONS at [["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems/byebug-9.0.6/lib/byebug/commands/frame.rb", 954]] @@ -143,24 +249,55 @@ Loading staging environment (Rails M.m.p) irb: warn: can't alias context from irb_context. ``` Find out what gems may be causing it by defining `context`! + ``` >> require 'gem_bench' => true >> bad_context_maybes = GemBench.find(look_for_regex: /def context/).starters [GemBench] Will search for gems in ["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@global/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@foss/bundler/gems"] [GemBench] Detected 11 loaded gems + 2 loaded gems which GemBench is configured to ignore. => [byebug, diff-lcs] ``` + Then find the file with the first occurrence of the regex in each: + ``` >> bad_context_maybes.map { |bcm| bcm.stats.map(&:first) } => [["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems/byebug-9.0.6/lib/byebug/command.rb"], ["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems/diff-lcs-1.3/lib/diff/lcs/hunk.rb"]] ``` +### Find what gems have `RAILS_ENV` specific code! + +Let's try to find what libraries might be using a conditional guard to alter their behavior in a specific Rails environment. + +``` +# Not a perfect regex, but pretty good: https://rubular.com/r/b7tdIoYOVQM2RR +# RAILS_ENV == "development" +# Rails.env.development? +# Rails.env == "development" +# ENV["RAILS_ENV"] == "development" +# ENV.fetch("RAILS_ENV") == "development" +>> require "gem_bench" +=> true +>> conditional_rails_behavior_regex = /(ENV(\["|\.fetch\("))?rails(_|\.)env("\]|"\))?( == "|\.)development/i +>> conditional_rails_behavior = GemBench.find(look_for_regex: conditional_rails_behavior_regex).starters +=> [rack, actionpack, actioncable, actionmailer, rubocop, railties, rubocop-ruby2_7, sass, sass-rails] +>> print conditional_rails_behavior.map {|gem| "#{gem.name} has Rails.env condition in #{gem.stats}" }.join("\n") +rack has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rack-mini-profiler-3.1.0/lib/mini_profiler_rails/railtie.rb", 1154]] +actionpack has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/actionpack-3.2.22.5/lib/action_controller/metal/force_ssl.rb", 1377]] +actioncable has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/actioncable-5.2.8.1/lib/action_cable/engine.rb", 886]] +actionmailer has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/actionmailer-7.0.5/lib/action_mailer/railtie.rb", 807]] +rubocop has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-ruby2_2-2.0.5/lib/rubocop/ruby2_2/railtie.rb", 131]] +railties has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/railties-3.2.22.5/lib/rails.rb", 2478]] +rubocop-ruby2_7 has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-ruby2_7-2.0.5/lib/rubocop/ruby2_7/railtie.rb", 131]] +sass has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/sass-rails-5.1.0/lib/sass/rails/railtie.rb", 3349]] +sass-rails has Rails.env condition in [["/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/sass-rails-5.1.0/lib/sass/rails/railtie.rb", 3349]] +``` + ### More Different Example! Fire up an `irb` session or a `rails console` and then: >> require 'gem_bench' @@ -220,11 +357,11 @@ In order to *also* see list gems may *not* be required at boot time you need to: 1. Make sure you are in the root of a project with a Gemfile 2. Make sure the gem is actually a dependency in the Gemfile -So here's a [*fat* Gemfile][bundle-group-pattern] weighing in at 265 gem dependencies. We'll use it for this example: +So here's a [fat Gemfile][bundle-group-pattern] weighing in at 265 gem dependencies. We'll use it for this example: ∴ bundle exec rails console Welcome to RAILS. You are using ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.1]. Have fun ;) Loading development environment (Rails 3.2.13) [1] pry(main)> a = GemBench.check({verbose: true}) @@ -380,15 +517,16 @@ This gem determines which gems need to be loaded at Rails' boot time by looking for Railties and Engines. A future version will also look for initializers, because gems which have code that runs (e.g. configuration) in an initializer also need to be loaded at boot time. ## Contributors -[![Contributors](https://contrib.rocks/image?repo=pboling/gitmoji-regex)][🖐contributors] +[![Contributors][🖐contributors-img]][🖐contributors] -Made with [contributors-img][contrib-rocks]. +Made with [contributors-img][🖐contrib-rocks]. +[🖐contrib-rocks]: https://contrib.rocks [🖐contributors]: https://github.com/pboling/gem_bench/graphs/contributors -[contrib-rocks]: https://contrib.rocks +[🖐contributors-img]: https://contrib.rocks/image?repo=pboling/gem_bench ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md)