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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #detect ⇒ Object
- #detect_from_bundler ⇒ Object
- #detect_from_gem ⇒ Object
- #detect_from_loadpath ⇒ Object
-
#initialize(name, options) ⇒ LibraryLocator
constructor
A new instance of LibraryLocator.
Methods included from BundlerSupport
Constructor Details
#initialize(name, options) ⇒ LibraryLocator
Returns a new instance of LibraryLocator.
20 21 22 23 |
# File 'lib/reditor/library_locator.rb', line 20 def initialize(name, ) @name = name @options = {global: false}.merge() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/reditor/library_locator.rb', line 18 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/reditor/library_locator.rb', line 18 def @options end |
Class Method Details
.detect(name, options = {}) ⇒ Object
7 8 9 |
# File 'lib/reditor/library_locator.rb', line 7 def detect(name, = {}) new(name.to_s, ).detect end |
.detect!(name, options = {}) ⇒ Object
11 12 13 |
# File 'lib/reditor/library_locator.rb', line 11 def detect!(name, = {}) detect(name, ) or raise LibraryNotFound, "Can't detect library `#{name}'." end |
Instance Method Details
#detect ⇒ Object
25 26 27 |
# File 'lib/reditor/library_locator.rb', line 25 def detect detect_from_bundler || detect_from_loadpath || detect_from_gem end |
#detect_from_bundler ⇒ Object
29 30 31 32 33 34 |
# File 'lib/reditor/library_locator.rb', line 29 def detect_from_bundler return nil if [:global] return nil unless spec = bundler_specs.find {|spec| spec.name == name } Pathname(spec.full_gem_path) end |
#detect_from_gem ⇒ Object
46 47 48 49 50 51 52 |
# 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 ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/reditor/library_locator.rb', line 36 def detect_from_loadpath basename = "#{name}.rb" $LOAD_PATH.map {|path| full_path = File.(path + '/' + basename) Pathname(full_path) }.detect(&:exist?) end |