Sha256: b8ef75519c5a1fd6b45a55ba39c9fe02dbd17f6c2e33d89fb1443391b000a234

Contents?: true

Size: 1.09 KB

Versions: 60

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Ibrain
  # Configuration point for User model implementation.
  #
  # `Ibrain::UserClassHandle` allows you to configure your own implementation of a
  # User class or use an extension like `ibrain-auth`.
  #
  # @note Placeholder for name of Ibrain.user_class to ensure later evaluation at
  #  runtime.
  #
  #  Unfortunately, it is possible for classes to get loaded before
  #  Ibrain.user_class has been set in the initializer. As a result, they end up
  #  with class_name: "" in their association definitions. For obvious reasons,
  #  that doesn't work.
  #
  #  For now, Rails does not call to_s on the instance passed in until runtime.
  #  So this little hack provides a wrapper around Ibrain.user_class so that we
  #  can basically lazy-evaluate it. Yay! Problem solved forever.
  class UserClassHandle
    # @return [String] the name of the user class as a string.
    # @raise [RuntimeError] if Ibrain.user_class is nil
    def to_s
      fail "'Ibrain.user_class' has not been set yet." unless Ibrain.user_class

      "::#{Ibrain.user_class}"
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
ibrain-core-0.5.15 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.13 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.12 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.10 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.9 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.8 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.7 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.6 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.5 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.4 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.3 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.2 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.1 lib/ibrain/user_class_handle.rb
ibrain-core-0.5.0 lib/ibrain/user_class_handle.rb
ibrain-core-0.4.9 lib/ibrain/user_class_handle.rb
ibrain-core-0.4.8 lib/ibrain/user_class_handle.rb
ibrain-core-0.4.7 lib/ibrain/user_class_handle.rb
ibrain-core-0.4.5 lib/ibrain/user_class_handle.rb
ibrain-core-0.4.4 lib/ibrain/user_class_handle.rb
ibrain-core-0.4.3 lib/ibrain/user_class_handle.rb