Class: Rdm::SourceLocator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SourceLocator

Returns a new instance of SourceLocator.



8
9
10
# File 'lib/rdm/source_locator.rb', line 8

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/rdm/source_locator.rb', line 7

def path
  @path
end

Class Method Details

.locate(path) ⇒ Object



3
4
5
# File 'lib/rdm/source_locator.rb', line 3

def self.locate(path)
  Rdm::SourceLocator.new(path).locate
end

Instance Method Details

#find_source_path_in_hierarchy(some_path) ⇒ Object



16
17
18
19
20
21
# File 'lib/rdm/source_locator.rb', line 16

def find_source_path_in_hierarchy(some_path)
  some_path = File.expand_path(some_path)
  raise Rdm::Errors::SourceFileDoesNotExist, path if some_path == '/'
  return potential_file(some_path) if present?(some_path)
  find_source_path_in_hierarchy(File.dirname(some_path))
end

#locateObject



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

def locate
  find_source_path_in_hierarchy(path)
end

#potential_file(some_path) ⇒ Object



27
28
29
# File 'lib/rdm/source_locator.rb', line 27

def potential_file(some_path)
  File.join(some_path, Rdm::SOURCE_FILENAME)
end

#present?(some_path) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rdm/source_locator.rb', line 23

def present?(some_path)
  File.exist?(potential_file(some_path))
end