Files
ubicloud/lib/semaphore_methods.rb
Jeremy Evans 191bf600f9 Split ResourceMethods, SemaphoreMethods, and HealthMonitorMethods into separate files in lib
This will allow reloading of the files in the future (not enabled
in this commit).

This also found a couple pieces of uncovered code in ResourceMethods,
that were hidden because model.rb is excluded from coverage, so
add specs for them.
2024-12-31 11:25:47 -08:00

31 lines
620 B
Ruby

# frozen_string_literal: true
module SemaphoreMethods
def self.included(base)
base.class_eval do
one_to_many :semaphores, key: :strand_id
end
base.extend(ClassMethods)
end
module ClassMethods
def semaphore_names
@semaphore_names || []
end
def semaphore(*names)
(@semaphore_names ||= []).concat(names)
names.each do |sym|
name = sym.name
define_method :"incr_#{name}" do
Semaphore.incr(id, sym)
end
define_method :"#{name}_set?" do
semaphores.any? { |s| s.name == name }
end
end
end
end
end