Project

finder

0.0
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Finder is a general purpose file finder for Ruby. Finder can search RubyGems, Roll libraries and Ruby's standard $LOAD_PATH and system data directory for the active or the most current library files. It is especially useful for implementing library-based plugin systems.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 0
 Project Readme

Finder

ARCHIVED. Finder was a load-path file searcher that supported RubyGems, Rolls (now archived as Realms), and Ruby's site locations. With Rolls/Realms gone, its main differentiator vs. Gem.find_files is gone too.

The most interesting piece of Finder was Kernel#import and Kernel#import_relative — variants of require that evaluate the loaded script into the current scope instead of the toplevel, providing a partial workaround for Ruby's toplevel pollution of Object. That feature has been folded into main_like_module as of v0.3.0, where it fits more naturally alongside that library's discussion of Ruby's toplevel design quirks.

require 'main_like_module/import'

module MyApp
  import 'helpers'
end

No further development of finder is planned.

Finder is a straight-forward file finder for searching Ruby library paths. It can handle RubyGems, Rolls and Ruby's standard site locals. It is both more flexible and more robust the using Gem.find_files or searching the $LOAD_PATH manually.

Instructions

To find paths, simply provide a glob to the appropriate Finder function, and it will return all matches found within current or most recent versions of a library.

For example, a common use case for plug-in enabled application is to require all the files found in library load paths:

require 'finder'

Find.feature('myapp/*').each do |file|
  require(file)
end

This is basically equivalent to:

Find.load_path('myapp/*.rb', :relative=>true).each do |file|
  require(file)
end

Alternately you might load files only as needed. For instance, if a command-line option calls for it.

In addition Finder has two optional Kernel extensions: #import and #import_relative. These methods can be used like #require and #require_relative, but load code directory into the current scope instead of the toplevel.

require 'finder/import'

module My
  import('abbrev.rb')
emd

My::Abbrev::abbrev(['ruby'])
=> {"rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby", "ruby"=>"ruby"}

It is important to be careful when using #import to make sure loaded scripts behave as intended. For example, if abbrev.rb were to define itself using :: toplevel namespace indicators, i.e. ::Abbrev, then the above import would not work as demonstrated.

Copyrights

Finder is copyrighted opensource software.

Copyright (c) 2009 Rubyworks

It can be modified and redistributed in accordance with the terms of the BSD-2-Clause license.

See LICENSE.txt file for details.