Browse files

Revert "Consider methods added via attr_* no commands"

Althugh there is an issue in here, the current implementation is
very brittle as looking into the stacktrace is not guaranteed to
stay the same across different ruby versions and ruby implementations.

This reverts commit fb149e3.
  • Loading branch information...
1 parent 08265a3 commit 1c7cb623b1cdea50bc7e66878c82be31431991bb @josevalim josevalim committed Mar 26, 2013
Showing with 12 additions and 7 deletions.
  1. +12 −3 lib/thor/base.rb
  2. +0 −4 spec/base_spec.rb
View
15 lib/thor/base.rb
@@ -119,6 +119,18 @@ def register_klass_file(klass) #:nodoc:
end
module ClassMethods
+ def attr_reader(*) #:nodoc:
+ no_commands { super }
+ end
+
+ def attr_writer(*) #:nodoc:
+ no_commands { super }
+ end
+
+ def attr_accessor(*) #:nodoc:
+ no_commands { super }
+ end
+
# If you want to raise an error for unknown options, call check_unknown_options!
# This is disabled by default to allow dynamic invocations.
def check_unknown_options!
@@ -578,9 +590,6 @@ def method_added(meth)
# Return if it's not a public instance method
return unless public_method_defined?(meth.to_sym)
- # Return if attr_* added the method
- return if caller.first.to_s[/`attr_(reader|writer|accessor)'/]
-
return if @no_commands || !create_command(meth)
is_thor_reserved_word?(meth, :command)
View
4 spec/base_spec.rb
@@ -287,9 +287,5 @@ def hello
expect(capture(:stderr){ MyScript.start(["some_attribute"]) }).to match(/Could not find/)
expect(capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }).to match(/Could not find/)
end
-
- it "respects visibility" do
- expect(MyScript.public_instance_methods).to_not include(:private_attribute)
- end
end
end

0 comments on commit 1c7cb62

Please sign in to comment.