aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-06-30 03:50:47 -0700
committerJosé Valim <jose.valim@gmail.com>2011-06-30 03:50:47 -0700
commitd1b61883162278e334e2892d193b31395bb47032 (patch)
tree97f19c0de3dc1213432d1dd3e65e431b56e3f30c
parent539752a54cf3426c98e65136206df9f9553d9e73 (diff)
parentbf526c2dbeb73bf11553004e43889a804b72866d (diff)
downloadrails-d1b61883162278e334e2892d193b31395bb47032.tar.gz
rails-d1b61883162278e334e2892d193b31395bb47032.tar.bz2
rails-d1b61883162278e334e2892d193b31395bb47032.zip
Merge pull request #1690 from vijaydev/mattr_accessor_changes
Added instance_accessor: false to Module#mattr_accessor
-rw-r--r--activesupport/lib/active_support/core_ext/module/attribute_accessors.rb8
-rw-r--r--activesupport/test/core_ext/module/attribute_accessor_test.rb7
2 files changed, 13 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
index 871f5cef3b..be94ae1565 100644
--- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
@@ -12,7 +12,7 @@ class Module
end
EOS
- unless options[:instance_reader] == false
+ unless options[:instance_reader] == false || options[:instance_accessor] == false
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
def #{sym}
@@#{sym}
@@ -31,7 +31,7 @@ class Module
end
EOS
- unless options[:instance_writer] == false
+ unless options[:instance_writer] == false || options[:instance_accessor] == false
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
def #{sym}=(obj)
@@#{sym} = obj
@@ -53,6 +53,10 @@ class Module
# end
#
# AppConfiguration.google_api_key = "overriding the api key!"
+ #
+ # To opt out of the instance writer method, pass :instance_writer => false.
+ # To opt out of the instance reader method, pass :instance_reader => false.
+ # To opt out of both instance methods, pass :instance_accessor => false.
def mattr_accessor(*syms)
mattr_reader(*syms)
mattr_writer(*syms)
diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb
index 118fb070a0..29889b51e0 100644
--- a/activesupport/test/core_ext/module/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb
@@ -7,6 +7,7 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
mattr_accessor :foo
mattr_accessor :bar, :instance_writer => false
mattr_reader :shaq, :instance_reader => false
+ mattr_accessor :camp, :instance_accessor => false
end
@class = Class.new
@class.instance_eval { include m }
@@ -37,4 +38,10 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
assert_respond_to @module, :shaq
assert !@object.respond_to?(:shaq)
end
+
+ def test_should_not_create_instance_accessors
+ assert_respond_to @module, :camp
+ assert !@object.respond_to?(:camp)
+ assert !@object.respond_to?(:camp=)
+ end
end