module Finder::Find::Gem
RubyGems finder methods.
Public Instance Methods
data_path(match, options={})
click to toggle source
Search gem data paths.
@param [String] match
The file glob to match.
@param [Hash] options
Search options.
@return [Array<String>] List of absolute paths.
# File lib/finder/gem.rb, line 95 def data_path(match, options={}) specs = specifications(options) matches = [] specs.each do |spec| list = [] glob = File.join(spec.full_gem_path, 'data', match) list = Dir[glob] #.map{ |f| f.untaint } list = list.map{ |d| d.chomp('/') } matches.concat(list) # activate the library if activate flag spec.activate if options[:activate] && !list.empty? end matches end
load_path(match, options={})
click to toggle source
Search gem load paths.
@param [String] match
The file glob to match.
@param [Hash] options
Search options.
@option options [String] :from
Specific gem to search.
@option options [true,false] :absolute
Return absolute paths instead of relative to load path.
@option options [true,false] :activate
Activate the gems if it has matching files.
@return [Array<String>] List of paths.
# File lib/finder/gem.rb, line 59 def load_path(match, options={}) options = valid_load_options(options) specs = specifications(options) matches = [] specs.each do |spec| list = [] spec.require_paths.each do |path| glob = File.join(spec.full_gem_path, path, match) list = Dir[glob] #.map{ |f| f.untaint } list = list.map{ |d| d.chomp('/') } # return relative paths unless absolute flag if options[:relative] #not options[:absolute] # the extra '' in File.join adds a '/' to the end of the path list = list.map{ |f| f.sub(File.join(spec.full_gem_path, path, ''), '') } end matches.concat(list) end # activate the library if activate flag spec.activate if options[:activate] && !list.empty? end matches end
path(match, options={})
click to toggle source
Search gems.
@param [String] match
The file glob to match.
@param [Hash] options
Search options.
@option options [String] :from
Specific gem to search.
@return [Array<String>] List of absolute paths.
# File lib/finder/gem.rb, line 23 def path(match, options={}) specs = specifications(options) matches = [] specs.each do |spec| list = [] glob = File.join(spec.full_gem_path, match) list = Dir[glob] #.map{ |f| f.untaint } list = list.map{ |d| d.chomp('/') } matches.concat(list) # activate the library if activate flag spec.activate if options[:activate] && !list.empty? end matches end
Private Instance Methods
specifications(options)
click to toggle source
# File lib/finder/gem.rb, line 114 def specifications(options) name = options[:from] || options[:gem] if name criteria = [options[:version]].compact begin specs = [::Gem::Specification.find_by_name(name.to_s, *criteria)] rescue ::Gem::LoadError specs = [] end else specs = ::Gem::Specification.current_specs end return specs end