
module Devise
  module MultiEmail
    class AssociationManager

      attr_reader :name

      def initialize(klass, association_name)
        @klass = klass
        @name = association_name
      end

      def include_module(mod)
        model_class.__send__ :include, mod
      end

      def autosave_changes?
        reflection.options[:autosave] == true
      end

      def model_class
        unless reflection
          raise "#{@klass}##{name} association not found: It might be because your declaration is after `devise :multi_email_confirmable`."
        end

        @model_class ||= reflection.class_name.constantize
      end

      def reflection
        @reflection ||= @klass.reflect_on_association(name)
      end
    end
  end
end


module Devise
  module MultiEmail
    class AssociationManager

      attr_reader :name

      def initialize(klass, association_name)
        @klass = klass
        @name = association_name
      end

      def include_module(mod)
        model_class.__send__ :include, mod
      end

      def autosave_changes?
        reflection.options[:autosave] == true
      end

      def model_class
        @model_class ||= reflection.class_name.constantize
      end

      def reflection
        @reflection ||= @klass.reflect_on_association(name) ||
                        raise("#{@klass}##{name} association not found: It might be because your declaration is after `devise :multi_email_confirmable`.")
      end
    end
  end
end

Raise exception immediately when association doesn't exist
Raise exception immediately when association doesn't exist
