File tree Expand file tree Collapse file tree 3 files changed +13
-34
lines changed Expand file tree Collapse file tree 3 files changed +13
-34
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 @@ -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
You can’t perform that action at this time.
0 commit comments