Class: Arrow::Object

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/arrow/object.rb

Overview

This class is the abstract base class for all Arrow objects. Most of the Arrow classes inherit from this.

To Do

All of this stuff should really be factored out into mixins.

Authors

Please see the file LICENSE in the top-level directory for licensing details.

Class Method Summary collapse

Class Method Details

.deprecate_class_method(oldSym, newSym = oldSym) ⇒ Object

Like Object.deprecate_method, but for class methods.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/arrow/object.rb', line 68

def self::deprecate_class_method( oldSym, newSym=oldSym )
	warningMessage = ''

	# If the method is being removed, alias it away somewhere and build
	# an appropriate warning message. Otherwise, just build a warning
	# message.
	if oldSym == newSym
		newSym = ("__deprecated_" + oldSym.to_s + "__").to_sym
		warningMessage = "%s::%s is deprecated" %
			[ self.name, oldSym.to_s ]
		alias_class_method newSym, oldSym
	else
		warningMessage = "%s::%s is deprecated; use %s::%s instead" %
			[ self.name, oldSym.to_s, self.name, newSym.to_s ]
	end

	# Build the method that logs a warning and then calls the true
	# method.
	class_eval %Q{
		def self::#{oldSym.to_s}( *args, &block )
			Arrow::Logger.notice "warning: %s: #{warningMessage}" % [ caller(1) ]
			send( #{newSym.inspect}, *args, &block )
		rescue => err
			# Mangle exceptions to point someplace useful
			Kernel.raise err, err.message, err.backtrace[2..-1]
		end
	}
end

.deprecate_method(oldSym, newSym = oldSym) ⇒ Object

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.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/arrow/object.rb', line 32

def self::deprecate_method( oldSym, newSym=oldSym )
	warningMessage = ''

	# If the method is being removed, alias it away somewhere and build
	# an appropriate warning message. Otherwise, just build a warning
	# message.
	if oldSym == newSym
		newSym = ("__deprecated_" + oldSym.to_s + "__").to_sym
		warningMessage = "%s#%s is deprecated" %
			[ self.name, oldSym.to_s ]
		alias_method newSym, oldSym
	else
		warningMessage = "%s#%s is deprecated; use %s#%s instead" %
			[ self.name, oldSym.to_s, self.name, newSym.to_s ]
	end

	# Build the method that logs a warning and then calls the true
	# method.
	class_eval %Q{
		def #{oldSym.to_s}( *args, &block )
			self.log.notice "warning: %s: #{warningMessage}" % [ caller(1) ]
			send( #{newSym.inspect}, *args, &block )
		rescue => err
			# Mangle exceptions to point someplace useful
			Kernel.raise err, err.message, err.backtrace[2..-1]
		end
	}
rescue Exception => err
	# Mangle exceptions to point someplace useful
	frames = err.backtrace
	frames.shift while frames.first =~ /#{__FILE__}/
	Kernel.raise err, err.message, frames
end

.inherited(klass) ⇒ Object

Store the name of the file from which the inheriting klass is being loaded.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/arrow/object.rb', line 100

def self::inherited( klass )
	unless klass.instance_variables.include?( "@sourcefile" )
		sourcefile = caller(1).find {|frame|
			/inherited/ !~ frame
		}.sub( /^([^:]+):.*/, "\\1" )
		klass.instance_variable_set( "@sourcefile", sourcefile )
	end

	unless klass.respond_to?( :sourcefile )
		class << klass
			attr_reader :sourcefile
		end
	end
end