Module: Shiftable::ModSignature::SgMethods

Defined in:
lib/shiftable/mod_signature.rb

Instance Method Summary collapse

Instance Method Details

#has_relObject



121
122
123
# File 'lib/shiftable/mod_signature.rb', line 121

def has_rel
  associations[:has_one]
end

#precheckObject

Do not move record if a record already exists (we are shifting a “has_one” association, after all)



126
127
128
# File 'lib/shiftable/mod_signature.rb', line 126

def precheck
  options[:precheck]
end

#shift_data!(shift_to:, shift_from:, bang: false) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/shiftable/mod_signature.rb', line 130

def shift_data!(shift_to:, shift_from:, bang: false)
  validate_relationships
  shifting = ShiftingRecord.new(
    to: shift_to,
    from: shift_from,
    column: shift_column,
    base: base,
    wrapper: wrapper,
    bang: bang
  ) do
    !precheck || !shift_to.send(has_rel)
  end
  shifting.shift do
    before_shift&.call(shifting)
  end
end