::Object
This class is the abstract base class for all Arrow objects. Most of the Arrow classes inherit from this.
Like Object.deprecate_method, but for class methods.
# File /Users/ged/source/ruby/Arrow/lib/arrow/object.rb, line 118 118: def self::deprecate_class_method( oldSym, newSym=oldSym ) 119: warningMessage = '' 120: 121: # If the method is being removed, alias it away somewhere and build 122: # an appropriate warning message. Otherwise, just build a warning 123: # message. 124: if oldSym == newSym 125: newSym = ("__deprecated_" + oldSym.to_s + "__").intern 126: warningMessage = "%s::%s is deprecated" % 127: [ self.name, oldSym.to_s ] 128: alias_class_method newSym, oldSym 129: else 130: warningMessage = "%s::%s is deprecated; use %s::%s instead" % 131: [ self.name, oldSym.to_s, self.name, newSym.to_s ] 132: end 133: 134: # Build the method that logs a warning and then calls the true 135: # method. 136: class_eval %Q{ 137: def self::#{oldSym.to_s}( *args, &block ) 138: Arrow::Logger.notice "warning: %s: #{warningMessage}" % [ caller(1) ] 139: send( #{newSym.inspect}, *args, &block ) 140: rescue => err 141: # Mangle exceptions to point someplace useful 142: Kernel.raise err, err.message, err.backtrace[2..-1] 143: end 144: } 145: end
Create a method that warns of deprecation for an instance method. If newSym is specified, the method is being renamed, and this method acts like an alias_method that logs a warning; if not, it is being removed, and the target method will be aliased to an internal method and wrapped in a warning method with the original name.
# File /Users/ged/source/ruby/Arrow/lib/arrow/object.rb, line 82 82: def self::deprecate_method( oldSym, newSym=oldSym ) 83: warningMessage = '' 84: 85: # If the method is being removed, alias it away somewhere and build 86: # an appropriate warning message. Otherwise, just build a warning 87: # message. 88: if oldSym == newSym 89: newSym = ("__deprecated_" + oldSym.to_s + "__").intern 90: warningMessage = "%s#%s is deprecated" % 91: [ self.name, oldSym.to_s ] 92: alias_method newSym, oldSym 93: else 94: warningMessage = "%s#%s is deprecated; use %s#%s instead" % 95: [ self.name, oldSym.to_s, self.name, newSym.to_s ] 96: end 97: 98: # Build the method that logs a warning and then calls the true 99: # method. 100: class_eval %Q{ 101: def #{oldSym.to_s}( *args, &block ) 102: self.log.notice "warning: %s: #{warningMessage}" % [ caller(1) ] 103: send( #{newSym.inspect}, *args, &block ) 104: rescue => err 105: # Mangle exceptions to point someplace useful 106: Kernel.raise err, err.message, err.backtrace[2..-1] 107: end 108: } 109: rescue Exception => err 110: # Mangle exceptions to point someplace useful 111: frames = err.backtrace 112: frames.shift while frames.first =~ /#{__FILE__}/ 113: Kernel.raise err, err.message, frames 114: end
Store the name of the file from which the inheriting klass is being loaded.
# File /Users/ged/source/ruby/Arrow/lib/arrow/object.rb, line 150 150: def self::inherited( klass ) 151: unless klass.instance_variables.include?( "@sourcefile" ) 152: sourcefile = caller(1).find {|frame| 153: /inherited/ !~ frame 154: }.sub( /^([^:]+):.*/, "\\1" ) 155: klass.instance_variable_set( "@sourcefile", sourcefile ) 156: end 157: 158: unless klass.respond_to?( :sourcefile ) 159: class << klass 160: attr_reader :sourcefile 161: end 162: end 163: end
--- SEC00092
--- ""
--- - methods: - visibility: public aref: M000590 name: deprecate_class_method sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/object.rb, line 118</span>\n\ 118: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">deprecate_class_method</span>( <span class=\"ruby-identifier\">oldSym</span>, <span class=\"ruby-identifier\">newSym</span>=<span class=\"ruby-identifier\">oldSym</span> )\n\ 119: <span class=\"ruby-identifier\">warningMessage</span> = <span class=\"ruby-value str\">''</span>\n\ 120: \n\ 121: <span class=\"ruby-comment cmt\"># If the method is being removed, alias it away somewhere and build</span>\n\ 122: <span class=\"ruby-comment cmt\"># an appropriate warning message. Otherwise, just build a warning</span>\n\ 123: <span class=\"ruby-comment cmt\"># message.</span>\n\ 124: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">oldSym</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">newSym</span>\n\ 125: <span class=\"ruby-identifier\">newSym</span> = (<span class=\"ruby-value str\">"__deprecated_"</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">oldSym</span>.<span class=\"ruby-identifier\">to_s</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">"__"</span>).<span class=\"ruby-identifier\">intern</span>\n\ 126: <span class=\"ruby-identifier\">warningMessage</span> = <span class=\"ruby-value str\">"%s::%s is deprecated"</span> <span class=\"ruby-operator\">%</span>\n\ 127: [ <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">oldSym</span>.<span class=\"ruby-identifier\">to_s</span> ]\n\ 128: <span class=\"ruby-identifier\">alias_class_method</span> <span class=\"ruby-identifier\">newSym</span>, <span class=\"ruby-identifier\">oldSym</span>\n\ 129: <span class=\"ruby-keyword kw\">else</span>\n\ 130: <span class=\"ruby-identifier\">warningMessage</span> = <span class=\"ruby-value str\">"%s::%s is deprecated; use %s::%s instead"</span> <span class=\"ruby-operator\">%</span>\n\ 131: [ <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">oldSym</span>.<span class=\"ruby-identifier\">to_s</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">newSym</span>.<span class=\"ruby-identifier\">to_s</span> ]\n\ 132: <span class=\"ruby-keyword kw\">end</span>\n\ 133: \n\ 134: <span class=\"ruby-comment cmt\"># Build the method that logs a warning and then calls the true</span>\n\ 135: <span class=\"ruby-comment cmt\"># method.</span>\n\ 136: <span class=\"ruby-identifier\">class_eval</span> <span class=\"ruby-node\">%Q{\n\ 137: def self::#{oldSym.to_s}( *args, &block )\n\ 138: Arrow::Logger.notice "warning: %s: #{warningMessage}" % [ caller(1) ]\n\ 139: send( #{newSym.inspect}, *args, &block )\n\ 140: rescue => err\n\ 141: # Mangle exceptions to point someplace useful\n\ 142: Kernel.raise err, err.message, err.backtrace[2..-1]\n\ 143: end\n\ 144: }</span>\n\ 145: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Like <a href="Object.html#M000589">Object.deprecate_method</a>, but for class methods. </p> params: ( oldSym, newSym=oldSym ) - visibility: public aref: M000589 name: deprecate_method sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/object.rb, line 82</span>\n 82: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">deprecate_method</span>( <span class=\"ruby-identifier\">oldSym</span>, <span class=\"ruby-identifier\">newSym</span>=<span class=\"ruby-identifier\">oldSym</span> )\n 83: <span class=\"ruby-identifier\">warningMessage</span> = <span class=\"ruby-value str\">''</span>\n 84: \n 85: <span class=\"ruby-comment cmt\"># If the method is being removed, alias it away somewhere and build</span>\n 86: <span class=\"ruby-comment cmt\"># an appropriate warning message. Otherwise, just build a warning</span>\n 87: <span class=\"ruby-comment cmt\"># message.</span>\n 88: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">oldSym</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">newSym</span>\n 89: <span class=\"ruby-identifier\">newSym</span> = (<span class=\"ruby-value str\">"__deprecated_"</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">oldSym</span>.<span class=\"ruby-identifier\">to_s</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">"__"</span>).<span class=\"ruby-identifier\">intern</span>\n 90: <span class=\"ruby-identifier\">warningMessage</span> = <span class=\"ruby-value str\">"%s#%s is deprecated"</span> <span class=\"ruby-operator\">%</span>\n 91: [ <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">oldSym</span>.<span class=\"ruby-identifier\">to_s</span> ]\n 92: <span class=\"ruby-identifier\">alias_method</span> <span class=\"ruby-identifier\">newSym</span>, <span class=\"ruby-identifier\">oldSym</span>\n 93: <span class=\"ruby-keyword kw\">else</span>\n 94: <span class=\"ruby-identifier\">warningMessage</span> = <span class=\"ruby-value str\">"%s#%s is deprecated; use %s#%s instead"</span> <span class=\"ruby-operator\">%</span>\n 95: [ <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">oldSym</span>.<span class=\"ruby-identifier\">to_s</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">newSym</span>.<span class=\"ruby-identifier\">to_s</span> ]\n 96: <span class=\"ruby-keyword kw\">end</span>\n 97: \n 98: <span class=\"ruby-comment cmt\"># Build the method that logs a warning and then calls the true</span>\n 99: <span class=\"ruby-comment cmt\"># method.</span>\n\ 100: <span class=\"ruby-identifier\">class_eval</span> <span class=\"ruby-node\">%Q{\n\ 101: def #{oldSym.to_s}( *args, &block )\n\ 102: self.log.notice "warning: %s: #{warningMessage}" % [ caller(1) ]\n\ 103: send( #{newSym.inspect}, *args, &block )\n\ 104: rescue => err\n\ 105: # Mangle exceptions to point someplace useful\n\ 106: Kernel.raise err, err.message, err.backtrace[2..-1]\n\ 107: end\n\ 108: }</span>\n\ 109: <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">Exception</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">err</span>\n\ 110: <span class=\"ruby-comment cmt\"># Mangle exceptions to point someplace useful</span>\n\ 111: <span class=\"ruby-identifier\">frames</span> = <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>\n\ 112: <span class=\"ruby-identifier\">frames</span>.<span class=\"ruby-identifier\">shift</span> <span class=\"ruby-keyword kw\">while</span> <span class=\"ruby-identifier\">frames</span>.<span class=\"ruby-identifier\">first</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-node\">/#{__FILE__}/</span>\n\ 113: <span class=\"ruby-constant\">Kernel</span>.<span class=\"ruby-identifier\">raise</span> <span class=\"ruby-identifier\">err</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span>, <span class=\"ruby-identifier\">frames</span>\n\ 114: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Create a method that warns of deprecation for an instance method. If <tt>newSym</tt> is specified, the method is being renamed, and this method acts like an <tt>alias_method</tt> that logs a warning; if not, it is being removed, and the target method will be aliased to an internal method and wrapped in a warning method with the original name. </p> params: ( oldSym, newSym=oldSym ) - visibility: public aref: M000591 name: inherited sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/object.rb, line 150</span>\n\ 150: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">inherited</span>( <span class=\"ruby-identifier\">klass</span> )\n\ 151: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">instance_variables</span>.<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-value str\">"@sourcefile"</span> )\n\ 152: <span class=\"ruby-identifier\">sourcefile</span> = <span class=\"ruby-identifier\">caller</span>(<span class=\"ruby-value\">1</span>).<span class=\"ruby-identifier\">find</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">frame</span><span class=\"ruby-operator\">|</span>\n\ 153: <span class=\"ruby-regexp re\">/inherited/</span> <span class=\"ruby-operator\">!~</span> <span class=\"ruby-identifier\">frame</span>\n\ 154: }.<span class=\"ruby-identifier\">sub</span>( <span class=\"ruby-regexp re\">/^([^:]+):.*/</span>, <span class=\"ruby-value str\">"\\\\1"</span> )\n\ 155: <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">instance_variable_set</span>( <span class=\"ruby-value str\">"@sourcefile"</span>, <span class=\"ruby-identifier\">sourcefile</span> )\n\ 156: <span class=\"ruby-keyword kw\">end</span>\n\ 157: \n\ 158: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">respond_to?</span>( <span class=\"ruby-identifier\">:sourcefile</span> )\n\ 159: <span class=\"ruby-keyword kw\">class</span> <span class=\"ruby-operator\"><<</span> <span class=\"ruby-identifier\">klass</span>\n\ 160: <span class=\"ruby-identifier\">attr_reader</span> <span class=\"ruby-identifier\">:sourcefile</span>\n\ 161: <span class=\"ruby-keyword kw\">end</span>\n\ 162: <span class=\"ruby-keyword kw\">end</span>\n\ 163: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Store the name of the file from which the inheriting <tt>klass</tt> is being loaded. </p> params: ( klass ) category: Class type: Public
---
--- - name: SVNRev desc: |+ SVN Revision value: "%q$Rev: 437 $" - name: SVNId desc: |+ SVN Id value: "%q$Id: object.rb 437 2008-03-28 00:49:20Z deveiant $"
Generated with the Darkfish Rdoc Generator.