Module: Itemable::ActsAsItemable::ClassMethods

Defined in:
lib/itemable/acts_as_itemable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_itemable(sti: false, parents: true, children: true, child: true, parent: true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/itemable/acts_as_itemable.rb', line 6

def acts_as_itemable(sti: false, parents: true, children: true, child: true, parent: true)
  if sti
    self.table_name = "itemable_items"
    self.instance_variable_set('@finder_needs_type_condition', :true)
  end

  if children
    include ChildrenAssociation
    include HasManyItems
  end

  if child
    include ChildAssociation
    include HasOneItem
  end

  if parents
    include ParentsAssociation
    include BelongsToItems
  end

  if parent
    include ParentAssociation
    include BelongsToItem
  end
end