Class: RUtilAnts::URLCache::URLHandlers::LocalFile
- Inherits:
-
Object
- Object
- RUtilAnts::URLCache::URLHandlers::LocalFile
- Defined in:
- lib/rUtilAnts/URLHandlers/LocalFile.rb
Overview
Handler of file URLs
Class Method Summary collapse
-
.getMatchingRegexps ⇒ Object
Get a list of regexps matching the URL to get to this handler.
Instance Method Summary collapse
-
#getContent(iFollowRedirections) ⇒ Object
Get the content of the URL.
-
#getCorrespondingFileBaseName ⇒ Object
Get a corresponding file base name.
-
#getCRC ⇒ Object
Get the current CRC of the URL.
-
#getServerID ⇒ Object
Get the server ID.
-
#initialize(iURL) ⇒ LocalFile
constructor
Constructor.
Constructor Details
#initialize(iURL) ⇒ LocalFile
Constructor
Parameters:
-
iURL (String): The URL that this handler will manage
29 30 31 32 33 34 35 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 29 def initialize(iURL) @URL = iURL lURLMatch = iURL.match(/^file:\/\/([^\/]*)\/(.*)$/) if (lURLMatch != nil) @URL = lURLMatch[1] end end |
Class Method Details
.getMatchingRegexps ⇒ Object
Get a list of regexps matching the URL to get to this handler
Return:
-
list<Regexp>: The list of regexps matching URLs from this handler
19 20 21 22 23 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 19 def self.getMatchingRegexps return [ /^file:\/\/\/(.*)$/ ] end |
Instance Method Details
#getContent(iFollowRedirections) ⇒ Object
Get the content of the URL
Parameters:
-
iFollowRedirections (Boolean): Do we follow redirections while accessing the content ?
Return:
-
Integer: Type of content returned
-
Object: The content, depending on the type previously returned:
** Exception if CONTENT_ERROR: The corresponding error ** String if CONTENT_REDIRECT: The new URL ** String if CONTENT_STRING: The real content ** String if CONTENT_LOCALFILENAME: The name of the local file name storing the content ** String if CONTENT_LOCALFILENAME_TEMPORARY: The name of the temporary local file name storing the content
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 79 def getContent(iFollowRedirections) rContentFormat = nil rContent = nil if (File.exists?(@URL)) rContent = @URL rContentFormat = CONTENT_LOCALFILENAME else rContent = Errno::ENOENT.new(@URL) rContentFormat = CONTENT_ERROR end return rContentFormat, rContent end |
#getCorrespondingFileBaseName ⇒ Object
Get a corresponding file base name. This method has to make sure file extensions are respected, as it can be used for further processing.
Return:
-
String: The file name
63 64 65 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 63 def getCorrespondingFileBaseName return File.basename(@URL) end |
#getCRC ⇒ Object
Get the current CRC of the URL
Return:
-
Integer: The CRC
49 50 51 52 53 54 55 56 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 49 def getCRC # We consider the file's modification time if (File.exists?(@URL)) return File.mtime(@URL) else return 0 end end |
#getServerID ⇒ Object
Get the server ID
Return:
-
String: The server ID
41 42 43 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 41 def getServerID return nil end |