Forum: Rails Engines mixing troubles

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B2c94554798f93efc509f076d5ba8c9c?d=identicon&s=25 Josh Rickard (idrifter)
on 2006-12-16 21:08
Hello all.  I'm having some trouble trying to wrap my brain around an
issue I'm having with an authentication engine I'm developing.  I'm
trying to separate out my User model's functionality into a module so
that I can customize the user model in each rails application without
directly modifying the engine source.  I've been using the LoginEngine
as a blueprint for how to do this.

The problem is that I can't seem to set my class methods to being
protected or they won't be accessible from my instance methods.  When I
call change_password on a user it throws an error that try_credentials
is protected.  I've trimmed down the code to the parts that I think are
relevant.  Anyone know why this doesn't work, or if there is a different
way this should be done?

module AuthenticationEngine
  module AuthUser
    def self.included(base)
      base.class_eval {
        # attr, validation stuff, etc.
      }
      base.extend(ClassMethods)
    end
  end

  module ClassMethods
    protected
      def try_credentials(login_name, password)
        # try login
      end

    public
      # these work ok
  end

  # instance methods
  def change_password(current, changed)
    acct = self.class.try_credentials(read_attribute('login_name'),
current)
    # do other stuff
  end
end

class User < ActiveRecord::Base
  include AuthenticationEngine::AuthUser
end
This topic is locked and can not be replied to.