doc/classes/FileCache.src/M000378.html in ripxplore-0.12.0 vs doc/classes/FileCache.src/M000378.html in ripxplore-0.13.0
- old
+ new
@@ -3,25 +3,30 @@
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
- <title>random_file_system_image (FileCache)</title>
+ <title>get_url (FileCache)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File lib/FileCache.rb, line 102</span>
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">random_file_system_image</span>(<span class="ruby-identifier">collection_type</span>=<span class="ruby-keyword kw">nil</span>)
- <span class="ruby-identifier">all_image_urls</span>=<span class="ruby-identifier">file_system_image_urls_in_cache</span>
- <span class="ruby-identifier">all_image_urls</span>.<span class="ruby-identifier">length</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
- <span class="ruby-keyword kw">begin</span>
- <span class="ruby-identifier">index</span>=<span class="ruby-identifier">rand</span>(<span class="ruby-identifier">all_image_urls</span>.<span class="ruby-identifier">length</span>)
- <span class="ruby-identifier">image</span>=<span class="ruby-identifier">get_file_system_image</span>(<span class="ruby-identifier">all_image_urls</span>[<span class="ruby-identifier">index</span><span class="ruby-operator">%</span><span class="ruby-identifier">all_image_urls</span>.<span class="ruby-identifier">length</span>])
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">image</span> <span class="ruby-keyword kw">if</span> ((<span class="ruby-identifier">collection_type</span><span class="ruby-operator">==</span><span class="ruby-keyword kw">nil</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">image</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">collection_type</span>).<span class="ruby-identifier">length</span><span class="ruby-operator">></span><span class="ruby-value">0</span>))
- <span class="ruby-keyword kw">rescue</span> <span class="ruby-comment cmt">#silently swallow any exception
</span>
- <span class="ruby-keyword kw">end</span>
+ <pre><span class="ruby-comment cmt"># File lib/FileCache.rb, line 58</span>
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_url</span>(<span class="ruby-identifier">url</span>)
+ <span class="ruby-identifier">local_file_name</span>=<span class="ruby-identifier">cache_name_for_url</span>(<span class="ruby-identifier">url</span>)
+ <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">local_file_name</span>) <span class="ruby-keyword kw">then</span>
+ <span class="ruby-constant">RipXploreLog</span>.<span class="ruby-identifier">log</span> <span class="ruby-node">"downloading #{url}"</span>
+ <span class="ruby-identifier">remote_file</span>=<span class="ruby-identifier">open</span>(<span class="ruby-identifier">url</span>,<span class="ruby-value str">"rb"</span>)
+ <span class="ruby-identifier">local_file</span>=<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">local_file_name</span>,<span class="ruby-value str">"wb"</span>)
+ <span class="ruby-identifier">local_file</span><span class="ruby-operator"><<</span><span class="ruby-identifier">remote_file</span>.<span class="ruby-identifier">read</span>
+ <span class="ruby-identifier">local_file</span>.<span class="ruby-identifier">close</span>
+ <span class="ruby-identifier">local_file_info_filename</span>=<span class="ruby-node">"#{local_file_name}.info"</span>
+ <span class="ruby-identifier">local_file_info_file</span>=<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">local_file_info_filename</span>,<span class="ruby-value str">"w"</span>)
+ <span class="ruby-identifier">local_file_info_file</span><span class="ruby-operator"><<</span><span class="ruby-identifier">url</span>
+ <span class="ruby-identifier">local_file_info_file</span>.<span class="ruby-identifier">close</span>
<span class="ruby-keyword kw">end</span>
- <span class="ruby-identifier">raise</span> <span class="ruby-value str">'no suitable image found in cache'</span>
+ <span class="ruby-identifier">file</span>=<span class="ruby-constant">FileCacheItem</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">local_file_name</span>,<span class="ruby-value str">"rb"</span>)
+ <span class="ruby-identifier">file</span>.<span class="ruby-identifier">set_path</span>(<span class="ruby-identifier">url</span>)
+ <span class="ruby-identifier">file</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>
\ No newline at end of file