You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
691 B
30 lines
691 B
class CreateDiffRecordService < ApplicationService
|
|
attr_reader :user, :obj, :column_name, :after, :before
|
|
|
|
def initialize(user, obj, column_name, before, after)
|
|
@user = user
|
|
@obj = obj
|
|
@before = before
|
|
@after = after
|
|
@column_name = column_name
|
|
end
|
|
|
|
def call
|
|
ActiveRecord::Base.transaction do
|
|
diff_record = DiffRecord.create!(user: user, container: obj, column_name: column_name)
|
|
diff_record.create_diff_record_content!(content: diff_content)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def diff_content
|
|
content = ''
|
|
Diffy::Diff.new(before, after).each do |line|
|
|
next unless line =~ /^[\+-]/
|
|
|
|
content += line
|
|
end
|
|
content
|
|
end
|
|
end |