No release in over 3 years
ReferenceExtractor parses Ruby code to produce a graph of constant and file references that other tools can use for rules like layering or dependency checks.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 0
>= 0
>= 1.4.0
 Project Readme

🚧 [WIP] ReferenceExtractor [WIP] 🚧

Introduction

ReferenceExtractor parses Ruby files and returns the constants they reference, using your Zeitwerk autoloaders to resolve what lives where. It gives you a graph you can use for architecture rules like layering or dependency checks.

ReferenceExtractor is in prototype stage. It works in general but is not battle tested.

It is based on packwerk.

Usage

extractor = ReferenceExtractor::Extractor.new(
  autoloaders: Rails.autoloaders,
  root_path: Rails.root
)

# From a string snippet
extractor.references_from_string("Order.find(1)")
# => [#<ReferenceExtractor::Reference constant=#<ReferenceExtractor::ConstantContext name=\"::Order\" ...>>]

# From a file relative to root_path
extractor.references_from_file("app/models/user.rb")
# => [#<ReferenceExtractor::Reference ...>, ...]

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Publishing to RubyGems

  1. Update the version in lib/reference_extractor/version.rb. Push / merge to main.

  2. Build the gem:

    gem build reference_extractor.gemspec

    This should produce reference_extractor-<version>.gem.

  3. Sign in to RubyGems (only needed once):

    gem signin
  4. Push the built gem:

    gem push reference_extractor-<version>.gem
  5. Tag the release:

    git tag v<version> && git push origin v<version>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/exterm/reference_extractor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the ReferenceExtractor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.