Skip to content
This repository
Newer
Older
100644 39 lines (33 sloc) 1.401 kb
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
1 class Module
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
2 # Declares an attribute reader backed by an internally-named instance variable.
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
3 def attr_internal_reader(*attrs)
f2e0b357 » thedarkone
2010-09-26 Use native attr_* macros for performance reasons.
4 attrs.each {|attr_name| attr_internal_define(attr_name, :reader)}
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
5 end
6
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
7 # Declares an attribute writer backed by an internally-named instance variable.
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
8 def attr_internal_writer(*attrs)
f2e0b357 » thedarkone
2010-09-26 Use native attr_* macros for performance reasons.
9 attrs.each {|attr_name| attr_internal_define(attr_name, :writer)}
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
10 end
11
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
12 # Declares an attribute reader and writer backed by an internally-named instance
ca941367 » lifo
2008-03-26 Improve documentation.
13 # variable.
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
14 def attr_internal_accessor(*attrs)
965ae90b » jeremy
2006-08-29 Eliminate Active Support warnings.
15 attr_internal_reader(*attrs)
16 attr_internal_writer(*attrs)
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
17 end
18
19 alias_method :attr_internal, :attr_internal_accessor
20
f28bd955 » jeremy
2009-04-22 Fix dependencies revealed by testing in isolation
21 class << self; attr_accessor :attr_internal_naming_format end
22 self.attr_internal_naming_format = '@_%s'
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
23
f28bd955 » jeremy
2009-04-22 Fix dependencies revealed by testing in isolation
24 private
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
25 def attr_internal_ivar_name(attr)
f28bd955 » jeremy
2009-04-22 Fix dependencies revealed by testing in isolation
26 Module.attr_internal_naming_format % attr
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
27 end
f2e0b357 » thedarkone
2010-09-26 Use native attr_* macros for performance reasons.
28
29 def attr_internal_define(attr_name, type)
30 internal_name = attr_internal_ivar_name(attr_name).sub(/\A@/, '')
31 class_eval do # class_eval is necessary on 1.9 or else the methods a made private
32 # use native attr_* methods as they are faster on some Ruby implementations
33 send("attr_#{type}", internal_name)
34 end
35 attr_name, internal_name = "#{attr_name}=", "#{internal_name}=" if type == :writer
36 alias_method attr_name, internal_name
37 remove_method internal_name
38 end
cfd9e05a » jeremy
2006-08-07 attr_internal to support namespacing and deprecation
39 end
Something went wrong with that request. Please try again.