Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Revert regressions found in 0.18.0 #316

Merged
merged 2 commits into from

3 participants

@josevalim

Revert regressions found in 0.18.0 as discussed here: 08265a3

josevalim added some commits
@josevalim josevalim 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 fb149e3dd8b71124d194cee81e5f5f1f788be6c5.
1c7cb62
@josevalim josevalim Allow calling private methods on template names
This is an expected feature from Thor. When rendering files,
Thor behaves like Sinatra. It works as if the file was embedded
in the current Thor class. Therefore, restricting the filename
to be just public methods is a wrong limitation that does not
fit with how Thor is meant to be used.
3c5a459
@coveralls

Coverage increased (+0.02%) when pulling 3c5a459 on josevalim:thor-reverts into 08265a3 on wycats:master.

View Details

@josevalim josevalim referenced this pull request from a commit
@sferik sferik Prepare for version 0.18.0 08265a3
@sferik sferik merged commit dc96d00 into erikhuda:master

1 check passed

Details default The Travis build passed
@tricknotes tricknotes referenced this pull request from a commit in tricknotes/rails
@rafaelfranca rafaelfranca Use thor master since 0.18.0 has a regression
See
erikhuda/thor@08265a3
for the discussion and erikhuda/thor#316 for the
fix
22caf39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @josevalim

    Revert "Consider methods added via attr_* no commands"

    josevalim authored
    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 fb149e3dd8b71124d194cee81e5f5f1f788be6c5.
  2. @josevalim

    Allow calling private methods on template names

    josevalim authored
    This is an expected feature from Thor. When rendering files,
    Thor behaves like Sinatra. It works as if the file was embedded
    in the current Thor class. Therefore, restricting the filename
    to be just public methods is a wrong limitation that does not
    fit with how Thor is meant to be used.
This page is out of date. Refresh to see the latest.
View
22 lib/thor/actions/empty_directory.rb
@@ -97,28 +97,12 @@ def destination=(destination)
#
# user.rb
#
- # The method referenced by %-string SHOULD be public. Otherwise you
- # get the exception with the corresponding error message.
+ # The method referenced can be either public or private.
#
def convert_encoded_instructions(filename)
filename.gsub(/%(.*?)%/) do |initial_string|
- call_public_method($1.strip) or initial_string
- end
- end
-
- # Calls `base`'s public method `sym`.
- # Returns:: result of `base.sym` or `nil` if `sym` wasn't found in
- # `base`
- # Raises:: Thor::PrivateMethodEncodedError if `sym` references
- # a private method.
- def call_public_method(sym)
- if base.respond_to?(sym)
- base.send(sym)
- elsif base.respond_to?(sym, true)
- raise Thor::PrivateMethodEncodedError,
- "Method #{base.class}##{sym} should be public, not private"
- else
- nil
+ method = $1.strip
+ base.respond_to?(method, true) ? base.send(method) : initial_string
end
end
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 lib/thor/error.rb
@@ -25,8 +25,4 @@ class RequiredArgumentMissingError < InvocationError
class MalformattedArgumentError < InvocationError
end
-
- # Raised when a user tries to call a private method encoded in templated filename.
- class PrivateMethodEncodedError < Error
- end
end
View
21 spec/actions/empty_directory_spec.rb
@@ -107,6 +107,16 @@ def base
expect(@action.send(:convert_encoded_instructions, "%file_name%.txt")).to eq("expected.txt")
end
+ it "accepts and executes a private %\w+% encoded instruction" do
+ @action.base.extend Module.new {
+ private
+ def private_file_name
+ "expected"
+ end
+ }
+ expect(@action.send(:convert_encoded_instructions, "%private_file_name%.txt")).to eq("expected.txt")
+ end
+
it "ignores an 'illegal' %\w+% encoded instruction" do
expect(@action.send(:convert_encoded_instructions, "%some_name%.txt")).to eq("%some_name%.txt")
end
@@ -114,17 +124,6 @@ def base
it "ignores incorrectly encoded instruction" do
expect(@action.send(:convert_encoded_instructions, "%some.name%.txt")).to eq("%some.name%.txt")
end
-
- it "raises an error if the instruction refers to a private method" do
- module PrivExt
- private
- def private_file_name
- "something_hidden"
- end
- end
- @action.base.extend(PrivExt)
- expect { @action.send(:convert_encoded_instructions, "%private_file_name%.txt") }.to raise_error Thor::PrivateMethodEncodedError
- end
end
end
end
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
Something went wrong with that request. Please try again.