Skip to content

Commit d29be49

Browse files
committed
Add rake task for creating document inferences.
1 parent 2fb0293 commit d29be49

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/tasks/documents.rake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,23 @@ namespace :documents do
170170
end
171171
end
172172
end
173+
174+
desc "Add document inference"
175+
task :add_document_inference, [:document_id, :inference_type, :inference_value, :inference_reason] => :environment do |t, args|
176+
doc = Document.find(args.document_id)
177+
if doc.nil?
178+
raise ActiveRecord::RecordNotFound
179+
end
180+
begin
181+
inference = DocumentInference.new(
182+
inference_type: args.inference_type,
183+
inference_value: args.inference_value,
184+
inference_reason: args.inference_reason,
185+
document: doc
186+
)
187+
inference.save!
188+
rescue ActiveRecord::RecordNotUnique
189+
p "Inference #{args.inference_type} already exists for document #{args.document_id}. Skipping creation."
190+
end
191+
end
173192
end

0 commit comments

Comments
 (0)