Class: Rdm::Packages::Locator

Inherits:
Object
  • Object
show all
Defined in:
lib/rdm/packages/locator.rb

Class Method Summary collapse

Class Method Details

.locate(path) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/rdm/packages/locator.rb', line 3

def locate(path)
  raise Rdm::Errors::PackageFileDoesNotFound, path if source_present?(path)
  raise Rdm::Errors::SourceFileDoesNotExist,  path if root_reached?(path)
  
  return path if package_present?(path)
  
  locate(File.dirname(path))
end

.package_present?(path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/rdm/packages/locator.rb', line 22

def package_present?(path)
  expected_package_file = File.join(path, Rdm::PACKAGE_FILENAME)

  File.exist?(expected_package_file)
end

.root_reached?(path) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rdm/packages/locator.rb', line 12

def root_reached?(path)
  File.expand_path(path) == '/'
end

.source_present?(path) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/rdm/packages/locator.rb', line 16

def source_present?(path)
  expected_source_file = File.join(path, Rdm::SOURCE_FILENAME)
  
  File.exist?(expected_source_file)
end