class Reditor::LibraryLocator
Attributes
name[R]
options[R]
Public Class Methods
detect(name, options = {})
click to toggle source
# File lib/reditor/library_locator.rb, line 7 def detect(name, options = {}) new(name.to_s, options).detect end
detect!(name, options = {})
click to toggle source
# File lib/reditor/library_locator.rb, line 11 def detect!(name, options = {}) detect(name, options) or raise LibraryNotFound, "Can't detect library `#{name}'." end
new(name, options)
click to toggle source
# File lib/reditor/library_locator.rb, line 20 def initialize(name, options) @name = name @options = {global: false}.merge(options) end
Public Instance Methods
detect()
click to toggle source
# File lib/reditor/library_locator.rb, line 25 def detect detect_from_bundler || detect_from_loadpath || detect_from_gem end
detect_from_bundler()
click to toggle source
# File lib/reditor/library_locator.rb, line 29 def detect_from_bundler return nil if options[:global] return nil unless spec = bundler_specs.find {|spec| spec.name == name } Pathname(spec.full_gem_path) end
detect_from_gem()
click to toggle source
# File lib/reditor/library_locator.rb, line 46 def detect_from_gem spec = Gem::Specification.find_by_name(name) Pathname(spec.full_gem_path) rescue Gem::LoadError # NOP (Gem couldn't find #{name} gem) end
detect_from_loadpath()
click to toggle source
# File lib/reditor/library_locator.rb, line 36 def detect_from_loadpath basename = "#{name}.rb" $LOAD_PATH.map {|path| full_path = File.expand_path(path + '/' + basename) Pathname(full_path) }.detect(&:exist?) end