親アプリケーションのユーザーモデルとの関係を確立するために「動作」形式を使用するRailsエンジンを構築しています。
module Cornerstone
module ActsAsCornerstoneUser
extend ActiveSupport::Concern
module ClassMethods
def acts_as_cornerstone_user(options = {})
#= Associations
has_many :cornerstone_discussions
#= Options
Cornerstone::Config.auth_with << options[:auth_with] if options[:auth_with]
Cornerstone::Config.auth_with.flatten!
end
end
module InstanceMethods
end
end
ActiveRecord::Base.send :include, ActsAsCornerstoneUser
end
開発者がオプションを使用してヘルパーメソッド名を指定できるようにしたいと思い:auth_with
ます。開発者は、親アプリケーションで、そのセッションのサインインしたユーザーを返すヘルパーメソッドを指定するという考え方です。
私の質問は、開発者がauth_with
オプションを指定したら、その親アプリケーションのメソッドをどのように呼び出すことができますか?
親アプリケーションのサインインしたユーザーを取得するためのより良いアプローチはありますか?単に呼び出すことに依存しないように、できるだけ柔軟にしたいと思いcurrent_user
ます。