Class: Reditor::LibraryLocator
- Inherits:
-
Object
- Object
- Reditor::LibraryLocator
- Defined in:
- lib/reditor/library_locator.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #detect ⇒ Object
- #detect_from_bundler ⇒ Object
- #detect_from_gem ⇒ Object
- #detect_from_loadpath ⇒ Object
-
#initialize(name) ⇒ LibraryLocator
constructor
A new instance of LibraryLocator.
Constructor Details
#initialize(name) ⇒ LibraryLocator
Returns a new instance of LibraryLocator.
12 13 14 |
# File 'lib/reditor/library_locator.rb', line 12 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/reditor/library_locator.rb', line 10 def name @name end |
Class Method Details
.detect(name) ⇒ Object
6 7 8 |
# File 'lib/reditor/library_locator.rb', line 6 def self.detect(name) new(name.to_s).detect end |
Instance Method Details
#detect ⇒ Object
16 17 18 |
# File 'lib/reditor/library_locator.rb', line 16 def detect detect_from_bundler || detect_from_loadpath || detect_from_gem end |
#detect_from_bundler ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/reditor/library_locator.rb', line 20 def detect_from_bundler require 'bundler' return nil unless spec = Bundler.load.specs.find {|spec| spec.name == name } Pathname(spec.full_gem_path) rescue NameError, Bundler::GemNotFound, Bundler::GemfileNotFound # NOP (probably it's not available bundler project) end |
#detect_from_gem ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/reditor/library_locator.rb', line 40 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 ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/reditor/library_locator.rb', line 30 def detect_from_loadpath basename = "#{name}.rb" $LOAD_PATH.map {|path| full_path = File.(path + '/' + basename) Pathname(full_path) }.detect(&:exist?) end |