Class: Proteus::FileHelper

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

Constant Summary collapse

DEFAULT_PATH =

The default path to search for definitions

File.expand_path( File.join(File.dirname(__FILE__), 'defs') )

Class Method Summary collapse

Class Method Details

.find_definition(class_path, path = nil) ⇒ Object

Find a definition file.

class_path: the full path of the class, including all namespaces



68
69
70
71
72
73
74
75
# File 'lib/FileHelper.rb', line 68

def self.find_definition( class_path, path = nil )
  path = path || DEFAULT_PATH
  
  file_path = class_path.join('/') + '.def'
  
  # Search the PATH for the file
  return self.find_file( file_path, path )
end

.find_file(target, path = nil) ⇒ Object

Find a file on the path.

target: the file to search for path: the path (standard UNIX path variable) to search

Returns:

  • Returns the path to the file.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/FileHelper.rb', line 45

def self.find_file( target, path = nil )
  path = path || DEFAULT_PATH
  
  path = path.split(':')
  
  for filepath in path
    
    candidate = File.join( filepath, target )
    
    if ( File.file?(candidate) )
      return candidate
    end
    
  end
  
  return nil
end