Registry applet filemap data structure.
Create a new Arrow::AppletRegistry::AppletFile for the applet at the given path.
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 53 53: def initialize( path ) 54: @path = path 55: @uris = [] 56: @appletclasses = nil 57: @timestamp = File.mtime( path ) 58: @exception = nil 59: @loadTime = Time.at( 0 ) 60: end
Returns an Array of Arrow::Applet classes loaded from this file, loading them if they haven‘t already been loaded.
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 94 94: def appletclasses 95: unless @appletclasses 96: self.log.debug "Loading applet classes from #{@path}" 97: @appletclasses = Arrow::Applet.load( @path ) 98: end 99: 100: rescue ::Exception => err 101: @exception = err 102: frames = self.filtered_backtrace 103: self.log.error "%s failed to load: %s" % [ path, err.message ] 104: self.log.debug " " + frames.collect {|frame| "[%s]" % frame}.join(" ") 105: @appletclasses = [] 106: ensure 107: return @appletclasses 108: end
Return the line of the exception that occurred while loading the applet, if any. If there was no exception, this method returns nil.
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 168 168: def exception_line 169: return nil unless @exception 170: targetline = nil 171: line = nil 172: 173: # ScriptErrors have the target line in the message; everything else 174: # is assumed to have it in the first line of the backtrace 175: if @exception.is_a?( ScriptError ) 176: targetline = @exception.message 177: else 178: targetline = @exception.backtrace.first 179: end 180: 181: # 182: if targetline =~ /.*:(\d+)(?::.*)?$/ 183: line = Integer( $1 ) 184: else 185: raise "Couldn't parse exception backtrace '%s' for error line." % 186: [ targetline ] 187: end 188: 189: return line 190: end
Return window_size lines surrounding the line of the applet‘s loading exception. If there was no loading exception, returns an empty Array.
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 196 196: def exception_source_window( window_size=DEFAULT_SOURCE_WINDOW_SIZE ) 197: return [] unless @exception 198: return self.source_window( self.exception_line, window_size ) 199: end
Return the lines of the applet exception‘s backtrace up to the first frame of the framework. Returns an empty Array if there is no current exception.
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 114 114: def filtered_backtrace 115: return [] unless @exception 116: 117: filtered = [] 118: @exception.backtrace.each do |frame| 119: break if frame.include?('lib/arrow/') 120: filtered.push( frame ) 121: end 122: 123: return filtered 124: end
Returns true if the corresponding file has changed since it was loaded
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 87 87: def has_changed? 88: @timestamp != File.mtime( path ) 89: end
Returns true if this file loaded without error
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 81 81: def loaded_okay? 82: @exception.nil? 83: end
Return the lines from the applet‘s source as an Array.
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 128 128: def source_lines 129: File.readlines( @path ) 130: end
Return window_size lines of the source from the applet surrounding the specified linenum as an Array of Hashes of the form:
{ :source => <line of source code>, :linenum => <line number>, :target => <true if this is the target line> }
# File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 141 141: def source_window( linenum, window_size=DEFAULT_SOURCE_WINDOW_SIZE ) 142: linenum -= 1 143: before_line = linenum - (window_size / 2) 144: after_line = linenum + (window_size / 2.0).ceil 145: 146: before_line = 0 if before_line < 0 147: 148: self.log.debug "Reading lines %d-%d from %s for source window on line %d" % 149: [ before_line, after_line, @path, linenum + 1 ] 150: 151: rval = [] 152: lines = self.source_lines[ before_line .. after_line ] 153: lines.each_with_index do |line, i| 154: rval << { 155: :source => line.chomp, 156: :linenum => before_line + i + 1, 157: :target => (before_line + i) == linenum, 158: } 159: end 160: 161: return rval 162: end
--- SEC00020
--- ""
--- - name: exception rw: RW a_desc: |+ The <a href="../Exception.html">Exception</a> object that was thrown when trying to load this file, if any - name: path rw: R a_desc: |+ The fully-qualified path to the applet file - name: timestamp rw: R a_desc: |+ A Time object representing the modification time of the file when it was loaded - name: uris rw: R a_desc: |+ An Array of URIs that applets contained in this file are mapped to
--- - methods: - visibility: public aref: M000396 name: new sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 53</span>\n\ 53: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">path</span> )\n\ 54: <span class=\"ruby-ivar\">@path</span> = <span class=\"ruby-identifier\">path</span>\n\ 55: <span class=\"ruby-ivar\">@uris</span> = []\n\ 56: <span class=\"ruby-ivar\">@appletclasses</span> = <span class=\"ruby-keyword kw\">nil</span>\n\ 57: <span class=\"ruby-ivar\">@timestamp</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">mtime</span>( <span class=\"ruby-identifier\">path</span> )\n\ 58: <span class=\"ruby-ivar\">@exception</span> = <span class=\"ruby-keyword kw\">nil</span>\n\ 59: <span class=\"ruby-ivar\">@loadTime</span> = <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">at</span>( <span class=\"ruby-value\">0</span> )\n\ 60: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Create a <a href="AppletFile.html#M000396">new</a> <a href="AppletFile.html">Arrow::AppletRegistry::AppletFile</a> for the applet at the given <tt>path</tt>. </p> params: ( path ) category: Class type: Public - methods: - visibility: public aref: M000399 name: appletclasses sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 94</span>\n 94: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">appletclasses</span>\n 95: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@appletclasses</span>\n 96: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-node\">"Loading applet classes from #{@path}"</span>\n 97: <span class=\"ruby-ivar\">@appletclasses</span> = <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Applet</span>.<span class=\"ruby-identifier\">load</span>( <span class=\"ruby-ivar\">@path</span> )\n 98: <span class=\"ruby-keyword kw\">end</span>\n 99: \n\ 100: <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Exception</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">err</span>\n\ 101: <span class=\"ruby-ivar\">@exception</span> = <span class=\"ruby-identifier\">err</span>\n\ 102: <span class=\"ruby-identifier\">frames</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">filtered_backtrace</span>\n\ 103: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">error</span> <span class=\"ruby-value str\">"%s failed to load: %s"</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">path</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span> ]\n\ 104: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">" "</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">frames</span>.<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">frame</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-value str\">"[%s]"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">frame</span>}.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">" "</span>)\n\ 105: <span class=\"ruby-ivar\">@appletclasses</span> = []\n\ 106: <span class=\"ruby-keyword kw\">ensure</span>\n\ 107: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@appletclasses</span>\n\ 108: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Returns an Array of <a href="../Applet.html">Arrow::Applet</a> classes loaded from this file, loading them if they haven‘t already been loaded. </p> params: () - visibility: public aref: M000403 name: exception_line sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 168</span>\n\ 168: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">exception_line</span>\n\ 169: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@exception</span>\n\ 170: <span class=\"ruby-identifier\">targetline</span> = <span class=\"ruby-keyword kw\">nil</span>\n\ 171: <span class=\"ruby-identifier\">line</span> = <span class=\"ruby-keyword kw\">nil</span>\n\ 172: \n\ 173: <span class=\"ruby-comment cmt\"># ScriptErrors have the target line in the message; everything else</span>\n\ 174: <span class=\"ruby-comment cmt\"># is assumed to have it in the first line of the backtrace</span>\n\ 175: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@exception</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">ScriptError</span> )\n\ 176: <span class=\"ruby-identifier\">targetline</span> = <span class=\"ruby-ivar\">@exception</span>.<span class=\"ruby-identifier\">message</span>\n\ 177: <span class=\"ruby-keyword kw\">else</span>\n\ 178: <span class=\"ruby-identifier\">targetline</span> = <span class=\"ruby-ivar\">@exception</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">first</span>\n\ 179: <span class=\"ruby-keyword kw\">end</span>\n\ 180: \n\ 181: <span class=\"ruby-comment cmt\"># </span>\n\ 182: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">targetline</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-regexp re\">/.*:(\\d+)(?::.*)?$/</span>\n\ 183: <span class=\"ruby-identifier\">line</span> = <span class=\"ruby-constant\">Integer</span>( <span class=\"ruby-identifier\">$1</span> )\n\ 184: <span class=\"ruby-keyword kw\">else</span>\n\ 185: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-value str\">"Couldn't parse exception backtrace '%s' for error line."</span> <span class=\"ruby-operator\">%</span>\n\ 186: [ <span class=\"ruby-identifier\">targetline</span> ]\n\ 187: <span class=\"ruby-keyword kw\">end</span>\n\ 188: \n\ 189: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">line</span>\n\ 190: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return the line of the exception that occurred while loading the applet, if any. If there was no exception, this method returns <tt>nil</tt>. </p> params: () - visibility: public aref: M000404 name: exception_source_window sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 196</span>\n\ 196: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">exception_source_window</span>( <span class=\"ruby-identifier\">window_size</span>=<span class=\"ruby-constant\">DEFAULT_SOURCE_WINDOW_SIZE</span> )\n\ 197: <span class=\"ruby-keyword kw\">return</span> [] <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@exception</span>\n\ 198: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">source_window</span>( <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">exception_line</span>, <span class=\"ruby-identifier\">window_size</span> )\n\ 199: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return <tt>window_size</tt> lines surrounding the line of the applet‘s loading exception. If there was no loading exception, returns an empty Array. </p> params: ( window_size=DEFAULT_SOURCE_WINDOW_SIZE ) - visibility: public aref: M000400 name: filtered_backtrace sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 114</span>\n\ 114: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">filtered_backtrace</span>\n\ 115: <span class=\"ruby-keyword kw\">return</span> [] <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@exception</span>\n\ 116: \n\ 117: <span class=\"ruby-identifier\">filtered</span> = []\n\ 118: <span class=\"ruby-ivar\">@exception</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">frame</span><span class=\"ruby-operator\">|</span>\n\ 119: <span class=\"ruby-keyword kw\">break</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">frame</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-value str\">'lib/arrow/'</span>)\n\ 120: <span class=\"ruby-identifier\">filtered</span>.<span class=\"ruby-identifier\">push</span>( <span class=\"ruby-identifier\">frame</span> )\n\ 121: <span class=\"ruby-keyword kw\">end</span>\n\ 122: \n\ 123: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">filtered</span>\n\ 124: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return the lines of the applet exception‘s backtrace up to the first frame of the framework. Returns an empty Array if there is no current exception. </p> params: () - visibility: public aref: M000398 name: has_changed? sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 87</span>\n\ 87: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">has_changed?</span>\n\ 88: <span class=\"ruby-ivar\">@timestamp</span> <span class=\"ruby-operator\">!=</span> <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">mtime</span>( <span class=\"ruby-identifier\">path</span> )\n\ 89: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Returns <tt>true</tt> if the corresponding file has changed since it was loaded </p> params: () - visibility: public aref: M000397 name: loaded_okay? sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 81</span>\n\ 81: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">loaded_okay?</span>\n\ 82: <span class=\"ruby-ivar\">@exception</span>.<span class=\"ruby-identifier\">nil?</span>\n\ 83: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Returns <tt>true</tt> if this file loaded without error </p> params: () - visibility: public aref: M000401 name: source_lines sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 128</span>\n\ 128: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">source_lines</span>\n\ 129: <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">readlines</span>( <span class=\"ruby-ivar\">@path</span> )\n\ 130: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return the lines from the applet‘s source as an Array. </p> params: () - visibility: public aref: M000402 name: source_window sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/appletregistry.rb, line 141</span>\n\ 141: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">source_window</span>( <span class=\"ruby-identifier\">linenum</span>, <span class=\"ruby-identifier\">window_size</span>=<span class=\"ruby-constant\">DEFAULT_SOURCE_WINDOW_SIZE</span> )\n\ 142: <span class=\"ruby-identifier\">linenum</span> <span class=\"ruby-operator\">-=</span> <span class=\"ruby-value\">1</span>\n\ 143: <span class=\"ruby-identifier\">before_line</span> = <span class=\"ruby-identifier\">linenum</span> <span class=\"ruby-operator\">-</span> (<span class=\"ruby-identifier\">window_size</span> <span class=\"ruby-operator\">/</span> <span class=\"ruby-value\">2</span>)\n\ 144: <span class=\"ruby-identifier\">after_line</span> = <span class=\"ruby-identifier\">linenum</span> <span class=\"ruby-operator\">+</span> (<span class=\"ruby-identifier\">window_size</span> <span class=\"ruby-operator\">/</span> <span class=\"ruby-value\">2.0</span>).<span class=\"ruby-identifier\">ceil</span>\n\ 145: \n\ 146: <span class=\"ruby-identifier\">before_line</span> = <span class=\"ruby-value\">0</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">before_line</span> <span class=\"ruby-operator\"><</span> <span class=\"ruby-value\">0</span>\n\ 147: \n\ 148: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Reading lines %d-%d from %s for source window on line %d"</span> <span class=\"ruby-operator\">%</span>\n\ 149: [ <span class=\"ruby-identifier\">before_line</span>, <span class=\"ruby-identifier\">after_line</span>, <span class=\"ruby-ivar\">@path</span>, <span class=\"ruby-identifier\">linenum</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">1</span> ]\n\ 150: \n\ 151: <span class=\"ruby-identifier\">rval</span> = []\n\ 152: <span class=\"ruby-identifier\">lines</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">source_lines</span>[ <span class=\"ruby-identifier\">before_line</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-identifier\">after_line</span> ]\n\ 153: <span class=\"ruby-identifier\">lines</span>.<span class=\"ruby-identifier\">each_with_index</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">line</span>, <span class=\"ruby-identifier\">i</span><span class=\"ruby-operator\">|</span>\n\ 154: <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\"><<</span> {\n\ 155: <span class=\"ruby-identifier\">:source</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">line</span>.<span class=\"ruby-identifier\">chomp</span>,\n\ 156: <span class=\"ruby-identifier\">:linenum</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">before_line</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">i</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">1</span>,\n\ 157: <span class=\"ruby-identifier\">:target</span> =<span class=\"ruby-operator\">></span> (<span class=\"ruby-identifier\">before_line</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">i</span>) <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">linenum</span>,\n\ 158: }\n\ 159: <span class=\"ruby-keyword kw\">end</span>\n\ 160: \n\ 161: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">rval</span>\n\ 162: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return <tt>window_size</tt> lines of the source from the applet surrounding the specified <tt>linenum</tt> as an Array of Hashes of the form: </p> <pre> { :source => <line of source code>, :linenum => <line number>, :target => <true if this is the target line> } </pre> params: ( linenum, window_size=DEFAULT_SOURCE_WINDOW_SIZE ) category: Instance type: Public
---
--- - name: DEFAULT_SOURCE_WINDOW_SIZE value: "20"
Generated with the Darkfish Rdoc Generator.