Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5.1: erb generator methods got private and break other gems #28275

Closed
januszm opened this issue Mar 3, 2017 · 2 comments
Closed

Rails 5.1: erb generator methods got private and break other gems #28275

januszm opened this issue Mar 3, 2017 · 2 comments
Labels

Comments

@januszm
Copy link

januszm commented Mar 3, 2017

In this commit:

commit d1daf4c31301f5f5917b877fd63a817f5f4608ed
Author: Akira Matsuda <ronnie@dio.jp>
Date:   Fri Dec 23 19:20:01 2016 +0900

    Privatize unneededly protected methods in Railties

diff --git a/railties/lib/rails/generators/erb.rb b/railties/lib/rails/generators/erb.rb
index d015020..d5e326d 100644
--- a/railties/lib/rails/generators/erb.rb
+++ b/railties/lib/rails/generators/erb.rb
@@ -3,7 +3,7 @@
 module Erb # :nodoc:
   module Generators # :nodoc:
     class Base < Rails::Generators::NamedBase #:nodoc:
-      protected
+      private
 
         def formats
           [format]

several methods, including format were changed to private from protected. Because of that they are no longer accessible in subclasses callable with receiver and cause troubles in other gems/generators that inherit from ERB

See: slim-template/slim-rails#139

@januszm
Copy link
Author

januszm commented Mar 3, 2017

cc: @amatsuda

@januszm januszm closed this as completed Mar 4, 2017
@januszm januszm reopened this Mar 4, 2017
@amatsuda
Copy link
Member

amatsuda commented Mar 4, 2017

Aww, thank you for reporting this.
It's not really related to subclassing (note that protected in Ruby is different from that in Java). The essential problem lies in self.format call here.
Here's a shorter code that reproducing the problem.

class A
  private def x() :x; end

  def foo(x = self.x)
    p x
  end
end

A.new.foo
#=> 28275.rb:4:in `foo': private method `x' called for #<A:0x007f9673944858> (NoMethodError)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants