Module: Evilution::GemDetector
- Defined in:
- lib/evilution/gem_detector.rb
Class Method Summary collapse
- .gem_entry_for(root, target_paths: nil) ⇒ Object
- .gem_root_for(path) ⇒ Object
- .gem_root_for_any(paths) ⇒ Object
- .reset_cache! ⇒ Object
Class Method Details
.gem_entry_for(root, target_paths: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/evilution/gem_detector.rb', line 29 def gem_entry_for(root, target_paths: nil) gem_name = gem_name_for(root, target_paths: target_paths) return nil unless gem_name dotted = File.join(root, "lib", "#{gem_name.tr("-", "/")}.rb") return dotted if File.file?(dotted) flat = File.join(root, "lib", "#{gem_name}.rb") return flat if File.file?(flat) nil end |
.gem_root_for(path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/evilution/gem_detector.rb', line 8 def gem_root_for(path) return nil if path.nil? dir = starting_dir(path) return nil if dir.nil? @mutex.synchronize do return @cache[dir] if @cache.key?(dir) @cache[dir] = walk_up(dir) end end |
.gem_root_for_any(paths) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/evilution/gem_detector.rb', line 21 def gem_root_for_any(paths) Array(paths).each do |path| root = gem_root_for(path) return root if root end nil end |
.reset_cache! ⇒ Object
42 43 44 |
# File 'lib/evilution/gem_detector.rb', line 42 def reset_cache! @mutex.synchronize { @cache.clear } end |