Forum: Rails Engines mixing troubles

Posted by 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.