Class: Impressionist::SetupAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/impressionist/setup_association.rb

Overview

Impressionist::SetupAssociation.new(entity).set

Instance Method Summary collapse

Constructor Details

#initialize(receiver) ⇒ SetupAssociation


4
5
6
# File 'lib/impressionist/setup_association.rb', line 4

def initialize(receiver)
  @receiver = receiver
end

Instance Method Details

#define_belongs_toObject


14
15
16
17
18
19
20
# File 'lib/impressionist/setup_association.rb', line 14

def define_belongs_to
  if ::Rails::VERSION::MAJOR.to_i >= 5
    receiver.belongs_to(:impressionable, :polymorphic => true, :optional => true)	         
  else
    receiver.belongs_to(:impressionable, :polymorphic => true)
  end
end

#include_attr_acc?Boolean

True or False Note toggle returns false if rails >= 4


10
11
12
# File 'lib/impressionist/setup_association.rb', line 10

def include_attr_acc?
  toggle && make_accessible
end

#setObject


22
23
24
25
# File 'lib/impressionist/setup_association.rb', line 22

def set
  define_belongs_to
  include_attr_acc?
end