Class: RUtilAnts::URLAccess::URLHandlers::LocalFile
- Inherits:
-
Object
- Object
- RUtilAnts::URLAccess::URLHandlers::LocalFile
- Defined in:
- lib/rUtilAnts/URLHandlers/LocalFile.rb
Overview
Handler of file URLs
Class Method Summary collapse
-
.get_matching_regexps ⇒ Object
Get a list of regexps matching the URL to get to this handler.
Instance Method Summary collapse
-
#get_content(iFollowRedirections) ⇒ Object
Get the content of the URL.
-
#get_corresponding_file_base_name ⇒ Object
Get a corresponding file base name.
-
#get_crc ⇒ Object
Get the current CRC of the URL.
-
#get_server_id ⇒ 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
24 25 26 27 28 29 30 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 24 def initialize(iURL) @URL = iURL lURLMatch = iURL.match(/^file:\/\/([^\/]*)\/(.*)$/) if (lURLMatch != nil) @URL = lURLMatch[1] end end |
Class Method Details
.get_matching_regexps ⇒ 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
14 15 16 17 18 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 14 def self.get_matching_regexps return [ /^file:\/\/\/(.*)$/ ] end |
Instance Method Details
#get_content(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
-
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 74 def get_content(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 |
#get_corresponding_file_base_name ⇒ 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
58 59 60 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 58 def get_corresponding_file_base_name return File.basename(@URL) end |
#get_crc ⇒ Object
Get the current CRC of the URL
- Return
-
Integer: The CRC
44 45 46 47 48 49 50 51 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 44 def get_crc # We consider the file's modification time if (File.exists?(@URL)) return File.mtime(@URL) else return 0 end end |
#get_server_id ⇒ Object
Get the server ID
- Return
-
String: The server ID
36 37 38 |
# File 'lib/rUtilAnts/URLHandlers/LocalFile.rb', line 36 def get_server_id return nil end |