Class: Reditor::LibraryLocator
- Inherits:
-
Object
- Object
- Reditor::LibraryLocator
- Includes:
- BundlerSupport
- 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.
Methods included from BundlerSupport
Constructor Details
#initialize(name) ⇒ LibraryLocator
Returns a new instance of LibraryLocator.
14 15 16 |
# File 'lib/reditor/library_locator.rb', line 14 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/reditor/library_locator.rb', line 12 def name @name end |
Class Method Details
.detect(name) ⇒ Object
8 9 10 |
# File 'lib/reditor/library_locator.rb', line 8 def self.detect(name) new(name.to_s).detect end |
Instance Method Details
#detect ⇒ Object
18 19 20 |
# File 'lib/reditor/library_locator.rb', line 18 def detect detect_from_bundler || detect_from_loadpath || detect_from_gem end |
#detect_from_bundler ⇒ Object
22 23 24 25 26 |
# File 'lib/reditor/library_locator.rb', line 22 def detect_from_bundler return nil unless spec = bundler_specs.find {|spec| spec.name == name } Pathname(spec.full_gem_path) end |
#detect_from_gem ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/reditor/library_locator.rb', line 38 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
28 29 30 31 32 33 34 35 36 |
# File 'lib/reditor/library_locator.rb', line 28 def detect_from_loadpath basename = "#{name}.rb" $LOAD_PATH.map {|path| full_path = File.(path + '/' + basename) Pathname(full_path) }.detect(&:exist?) end |