Skip to content

Commit 1c7cb62

Browse files
author
José Valim
committed
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.
1 parent 08265a3 commit 1c7cb62

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/thor/base.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ def register_klass_file(klass) #:nodoc:
119119
end
120120

121121
module ClassMethods
122+
def attr_reader(*) #:nodoc:
123+
no_commands { super }
124+
end
125+
126+
def attr_writer(*) #:nodoc:
127+
no_commands { super }
128+
end
129+
130+
def attr_accessor(*) #:nodoc:
131+
no_commands { super }
132+
end
133+
122134
# If you want to raise an error for unknown options, call check_unknown_options!
123135
# This is disabled by default to allow dynamic invocations.
124136
def check_unknown_options!
@@ -578,9 +590,6 @@ def method_added(meth)
578590
# Return if it's not a public instance method
579591
return unless public_method_defined?(meth.to_sym)
580592

581-
# Return if attr_* added the method
582-
return if caller.first.to_s[/`attr_(reader|writer|accessor)'/]
583-
584593
return if @no_commands || !create_command(meth)
585594

586595
is_thor_reserved_word?(meth, :command)

spec/base_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,5 @@ def hello
287287
expect(capture(:stderr){ MyScript.start(["some_attribute"]) }).to match(/Could not find/)
288288
expect(capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }).to match(/Could not find/)
289289
end
290-
291-
it "respects visibility" do
292-
expect(MyScript.public_instance_methods).to_not include(:private_attribute)
293-
end
294290
end
295291
end

0 commit comments

Comments
 (0)