aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-07 01:16:37 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-07 01:16:37 +0000
commitcfd9e05a2edf53bc92220cd91795a6b8f1029630 (patch)
tree28d1469c040fd261479c6bbe7ec62484e2ede961 /activesupport/lib/active_support
parent678f8cbb704ea9398a32289221de489027c6e66c (diff)
downloadrails-cfd9e05a2edf53bc92220cd91795a6b8f1029630.tar.gz
rails-cfd9e05a2edf53bc92220cd91795a6b8f1029630.tar.bz2
rails-cfd9e05a2edf53bc92220cd91795a6b8f1029630.zip
attr_internal to support namespacing and deprecation
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4692 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/module.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/module/attr_internal.rb31
2 files changed, 32 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb
index 45069f52af..8d48de53dd 100644
--- a/activesupport/lib/active_support/core_ext/module.rb
+++ b/activesupport/lib/active_support/core_ext/module.rb
@@ -1,5 +1,6 @@
require File.dirname(__FILE__) + '/module/inclusion'
require File.dirname(__FILE__) + '/module/attribute_accessors'
+require File.dirname(__FILE__) + '/module/attr_internal'
require File.dirname(__FILE__) + '/module/delegation'
require File.dirname(__FILE__) + '/module/introspection'
require File.dirname(__FILE__) + '/module/loading'
diff --git a/activesupport/lib/active_support/core_ext/module/attr_internal.rb b/activesupport/lib/active_support/core_ext/module/attr_internal.rb
new file mode 100644
index 0000000000..c793da7159
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/attr_internal.rb
@@ -0,0 +1,31 @@
+class Module
+ # Declare an attribute reader backed by an internally-named instance variable.
+ def attr_internal_reader(*attrs)
+ attrs.each do |attr|
+ module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
+ end
+ end
+
+ # Declare an attribute writer backed by an internally-named instance variable.
+ def attr_internal_writer(*attrs)
+ attrs.each do |attr|
+ module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
+ end
+ end
+
+ # Declare attributes backed by 'internal' instance variables names.
+ def attr_internal_accessor(*attrs)
+ attr_internal_reader *attrs
+ attr_internal_writer *attrs
+ end
+
+ alias_method :attr_internal, :attr_internal_accessor
+
+ private
+ mattr_accessor :attr_internal_naming_format
+ self.attr_internal_naming_format = '@_%s'
+
+ def attr_internal_ivar_name(attr)
+ attr_internal_naming_format % attr
+ end
+end