Sha256: a551c2af3fa9864236a96ea016afc98cd950bc8ca3d89aeae5af5cd6cfb23440

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

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

      # Specify a block with alternative behavior which should be
      # run when `autosave` is not enabled.
      def configure_autosave!(&block)
        unless autosave_enabled?
          if Devise::MultiEmail.autosave_emails?
            reflection.autosave = true
          else
            yield if block_given?
          end
        end
      end

      def autosave_enabled?
        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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
devise-multi_email-3.0.1 lib/devise/multi_email/association_manager.rb
devise-multi_email-3.0.0 lib/devise/multi_email/association_manager.rb
devise-multi_email-2.0.1 lib/devise/multi_email/association_manager.rb