ubicloud/model/semaphore.rb
Burak Yucesoy 6157fe829d Simplify UBID usage in models
Previously, to enable UBIDs, one would need to define ubid_type function in the
each respective model file. However, this function works same for each model;
the difference is it returns different constant. With some string manipulation,
it is possible to generate the name of the constant. Sequel and we already use
similar inflictions to make things feel more "magical", so I don't have much
concerns regarding generating constant names via string manipulation.

Thanks to this commit, we don't need to define ubid_type for each model anymore.
Similarly we also don't need to add new type to when/case block in ubid.rb

While doing this, I found two unused constants and removed them. Also slightly
modified two other constants' names to match it with the class names.

Finally, as a small bonus, we reduced the line count by 77 and unit tests now
complete 0.2 seconds faster. Possibly due to removing long when/case block.
2023-07-25 11:04:26 +03:00

14 lines
343 B
Ruby

# frozen_string_literal: true
require_relative "../model"
class Semaphore < Sequel::Model
include ResourceMethods
def self.incr(strand_id, name)
DB.transaction do
Strand.dataset.where(id: strand_id).update(schedule: Sequel::CURRENT_TIMESTAMP)
Semaphore.create_with_id(strand_id: strand_id, name: name)
end
end
end