Class: Shiftable::ShiftingPolymorphicRelation
- Inherits:
-
Shifting
- Object
- Shifting
- Shiftable::ShiftingPolymorphicRelation
show all
- Includes:
- Enumerable
- Defined in:
- lib/shiftable/shifting_polymorphic_relation.rb
Overview
Instance Attribute Summary
Attributes inherited from Shifting
#bang, #base, #column, #from, #result, #run_save, #shift_all_wrapper, #shift_each_wrapper, #to
Instance Method Summary
collapse
Methods inherited from Shifting
#initialize
Instance Method Details
#each(&block) ⇒ Object
20
21
22
|
# File 'lib/shiftable/shifting_polymorphic_relation.rb', line 20
def each(&block)
result.each(&block)
end
|
#found? ⇒ Boolean
16
17
18
|
# File 'lib/shiftable/shifting_polymorphic_relation.rb', line 16
def found?
result.any?
end
|
#polymorphic_id_column ⇒ Object
8
9
10
|
# File 'lib/shiftable/shifting_polymorphic_relation.rb', line 8
def polymorphic_id_column
column[:id_column]
end
|
#polymorphic_type_column ⇒ Object
12
13
14
|
# File 'lib/shiftable/shifting_polymorphic_relation.rb', line 12
def polymorphic_type_column
"#{column[:as]}_type"
end
|
#shift ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/shiftable/shifting_polymorphic_relation.rb', line 25
def shift
return false unless found?
each do |record|
record.send("#{polymorphic_id_column}=", to.id)
end
@run_save = yield if block_given?
return result unless run_save
run_save!
result
end
|