aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/class
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-01-28 01:18:51 +0000
committerRick Olson <technoweenie@gmail.com>2007-01-28 01:18:51 +0000
commit5e85a1c7f835249d276d6868a9520f803be46159 (patch)
treea928f33feb1e2be4ba7f21cfb5994f839cb75349 /activesupport/lib/active_support/core_ext/class
parenteca93d0970925a305c6ccc620df62aeb385938dc (diff)
downloadrails-5e85a1c7f835249d276d6868a9520f803be46159.tar.gz
rails-5e85a1c7f835249d276d6868a9520f803be46159.tar.bz2
rails-5e85a1c7f835249d276d6868a9520f803be46159.zip
Added :instance_writer option to #mattr_writer/accessor, #cattr_writer/accessor, and #class_inheritable_writer to skip the creation of the instance writer. [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6050 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/class')
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute_accessors.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb10
2 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 93a7d48f69..79247e00cb 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -3,6 +3,7 @@
class Class # :nodoc:
def cattr_reader(*syms)
syms.flatten.each do |sym|
+ next if sym.is_a?(Hash)
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym}
@@#{sym} = nil
@@ -20,6 +21,7 @@ class Class # :nodoc:
end
def cattr_writer(*syms)
+ options = syms.last.is_a?(Hash) ? syms.pop : {}
syms.flatten.each do |sym|
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym}
@@ -30,9 +32,11 @@ class Class # :nodoc:
@@#{sym} = obj
end
+ #{"
def #{sym}=(obj)
@@#{sym} = obj
end
+ " unless options[:instance_writer] == false }
EOS
end
end
diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
index bc8bf09ab2..3c5b2b8340 100644
--- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
+++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
@@ -9,6 +9,7 @@ end
class Class # :nodoc:
def class_inheritable_reader(*syms)
syms.each do |sym|
+ next if sym.is_a?(Hash)
class_eval <<-EOS
def self.#{sym}
read_inheritable_attribute(:#{sym})
@@ -22,43 +23,52 @@ class Class # :nodoc:
end
def class_inheritable_writer(*syms)
+ options = syms.last.is_a?(Hash) ? syms.pop : {}
syms.each do |sym|
class_eval <<-EOS
def self.#{sym}=(obj)
write_inheritable_attribute(:#{sym}, obj)
end
+ #{"
def #{sym}=(obj)
self.class.#{sym} = obj
end
+ " unless options[:instance_writer] == false }
EOS
end
end
def class_inheritable_array_writer(*syms)
+ options = syms.last.is_a?(Hash) ? syms.pop : {}
syms.each do |sym|
class_eval <<-EOS
def self.#{sym}=(obj)
write_inheritable_array(:#{sym}, obj)
end
+ #{"
def #{sym}=(obj)
self.class.#{sym} = obj
end
+ " unless options[:instance_writer] == false }
EOS
end
end
def class_inheritable_hash_writer(*syms)
+ options = syms.last.is_a?(Hash) ? syms.pop : {}
syms.each do |sym|
class_eval <<-EOS
def self.#{sym}=(obj)
write_inheritable_hash(:#{sym}, obj)
end
+ #{"
def #{sym}=(obj)
self.class.#{sym} = obj
end
+ " unless options[:instance_writer] == false }
EOS
end
end