File tree Expand file tree Collapse file tree 5 files changed +25
-41
lines changed Expand file tree Collapse file tree 5 files changed +25
-41
lines changed Original file line number Diff line number Diff line change @@ -97,28 +97,12 @@ def destination=(destination)
97
97
#
98
98
# user.rb
99
99
#
100
- # The method referenced by %-string SHOULD be public. Otherwise you
101
- # get the exception with the corresponding error message.
100
+ # The method referenced can be either public or private.
102
101
#
103
102
def convert_encoded_instructions ( filename )
104
103
filename . gsub ( /%(.*?)%/ ) do |initial_string |
105
- call_public_method ( $1. strip ) or initial_string
106
- end
107
- end
108
-
109
- # Calls `base`'s public method `sym`.
110
- # Returns:: result of `base.sym` or `nil` if `sym` wasn't found in
111
- # `base`
112
- # Raises:: Thor::PrivateMethodEncodedError if `sym` references
113
- # a private method.
114
- def call_public_method ( sym )
115
- if base . respond_to? ( sym )
116
- base . send ( sym )
117
- elsif base . respond_to? ( sym , true )
118
- raise Thor ::PrivateMethodEncodedError ,
119
- "Method #{ base . class } ##{ sym } should be public, not private"
120
- else
121
- nil
104
+ method = $1. strip
105
+ base . respond_to? ( method , true ) ? base . send ( method ) : initial_string
122
106
end
123
107
end
124
108
Original file line number Diff line number Diff line change @@ -119,6 +119,18 @@ def register_klass_file(klass) #:nodoc:
119
119
end
120
120
121
121
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
+
122
134
# If you want to raise an error for unknown options, call check_unknown_options!
123
135
# This is disabled by default to allow dynamic invocations.
124
136
def check_unknown_options!
@@ -578,9 +590,6 @@ def method_added(meth)
578
590
# Return if it's not a public instance method
579
591
return unless public_method_defined? ( meth . to_sym )
580
592
581
- # Return if attr_* added the method
582
- return if caller . first . to_s [ /`attr_(reader|writer|accessor)'/ ]
583
-
584
593
return if @no_commands || !create_command ( meth )
585
594
586
595
is_thor_reserved_word? ( meth , :command )
Original file line number Diff line number Diff line change @@ -25,8 +25,4 @@ class RequiredArgumentMissingError < InvocationError
25
25
26
26
class MalformattedArgumentError < InvocationError
27
27
end
28
-
29
- # Raised when a user tries to call a private method encoded in templated filename.
30
- class PrivateMethodEncodedError < Error
31
- end
32
28
end
Original file line number Diff line number Diff line change @@ -107,24 +107,23 @@ def base
107
107
expect ( @action . send ( :convert_encoded_instructions , "%file_name%.txt" ) ) . to eq ( "expected.txt" )
108
108
end
109
109
110
+ it "accepts and executes a private %\w +% encoded instruction" do
111
+ @action . base . extend Module . new {
112
+ private
113
+ def private_file_name
114
+ "expected"
115
+ end
116
+ }
117
+ expect ( @action . send ( :convert_encoded_instructions , "%private_file_name%.txt" ) ) . to eq ( "expected.txt" )
118
+ end
119
+
110
120
it "ignores an 'illegal' %\w +% encoded instruction" do
111
121
expect ( @action . send ( :convert_encoded_instructions , "%some_name%.txt" ) ) . to eq ( "%some_name%.txt" )
112
122
end
113
123
114
124
it "ignores incorrectly encoded instruction" do
115
125
expect ( @action . send ( :convert_encoded_instructions , "%some.name%.txt" ) ) . to eq ( "%some.name%.txt" )
116
126
end
117
-
118
- it "raises an error if the instruction refers to a private method" do
119
- module PrivExt
120
- private
121
- def private_file_name
122
- "something_hidden"
123
- end
124
- end
125
- @action . base . extend ( PrivExt )
126
- expect { @action . send ( :convert_encoded_instructions , "%private_file_name%.txt" ) } . to raise_error Thor ::PrivateMethodEncodedError
127
- end
128
127
end
129
128
end
130
129
end
Original file line number Diff line number Diff line change @@ -287,9 +287,5 @@ def hello
287
287
expect ( capture ( :stderr ) { MyScript . start ( [ "some_attribute" ] ) } ) . to match ( /Could not find/ )
288
288
expect ( capture ( :stderr ) { MyScript . start ( [ "some_attribute=" , "foo" ] ) } ) . to match ( /Could not find/ )
289
289
end
290
-
291
- it "respects visibility" do
292
- expect ( MyScript . public_instance_methods ) . to_not include ( :private_attribute )
293
- end
294
290
end
295
291
end
You can’t perform that action at this time.
0 commit comments