module LibsCatalog
LibsCatalog — discover shared lib/*.rb modules under lib/. Public: list Depends: (none) Tests: test/lib/libs_catalog_test.rb
Constants
- VENDOR_SEGMENT
Public Instance Methods
Source
# File lib/libs_catalog.rb, line 30 def apply_filter(names, filter) pattern = filter.to_s.strip return names if pattern.empty? glob = pattern.include?("*") ? pattern : "#{pattern}*" names.select { |name| File.fnmatch(glob, name, File::FNM_CASEFOLD) } end
Source
# File lib/libs_catalog.rb, line 13 def list(lib_dir:, filter: nil) pattern = File.join(lib_dir, "**", "*.rb") paths = Dir.glob(pattern).sort names = paths .reject { |path| path.include?(VENDOR_SEGMENT) } .map { |path| relative_name(path, lib_dir: lib_dir) } apply_filter(names, filter) end
Source
# File lib/libs_catalog.rb, line 23 def relative_name(path, lib_dir:) root = File.expand_path(lib_dir) rel = File.expand_path(path).sub(/\A#{Regexp.escape(root)}\/?/, "") rel.sub(/\.rb\z/, "") end