Class: Devise::MultiEmail::AssociationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/devise/multi_email/association_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, association_name) ⇒ AssociationManager

Returns a new instance of AssociationManager.



8
9
10
11
# File 'lib/devise/multi_email/association_manager.rb', line 8

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/devise/multi_email/association_manager.rb', line 6

def name
  @name
end

Instance Method Details

#autosave_enabled?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/devise/multi_email/association_manager.rb', line 29

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

#configure_autosave!(&block) ⇒ Object

Specify a block with alternative behavior which should be run when ‘autosave` is not enabled.



19
20
21
22
23
24
25
26
27
# File 'lib/devise/multi_email/association_manager.rb', line 19

def configure_autosave!(&block)
  unless autosave_enabled?
    if Devise::MultiEmail.autosave_emails?
      reflection.autosave = true
    else
      yield if block_given?
    end
  end
end

#include_module(mod) ⇒ Object



13
14
15
# File 'lib/devise/multi_email/association_manager.rb', line 13

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

#model_classObject



33
34
35
# File 'lib/devise/multi_email/association_manager.rb', line 33

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

#reflectionObject



37
38
39
40
# File 'lib/devise/multi_email/association_manager.rb', line 37

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