This repository has been archived on 2020-10-16. You can view files and clone it, but cannot push or open issues or pull requests.
counter/app/models/cluster.rb

42 lines
649 B
Ruby
Raw Normal View History

2020-05-23 03:54:29 +00:00
# frozen_string_literal: true
require 'securerandom'
# A collective for a tally
class Cluster
attr_reader :count, :name, :status, :uuid, :created_on
2020-05-23 03:54:29 +00:00
@@clusters = {}
def initialize(name)
@uuid = SecureRandom.uuid
@name = name
@count = 0
@status = :open
@mutex = Mutex.new
@created_on = Time.new
2020-05-23 03:54:29 +00:00
@@clusters[@uuid] = self
end
def increment(var = 1)
@mutex.synchronize do
@count += var
end
end
def decrement(var = 1)
@mutex.synchronize do
@count -= var
end
end
class << self
def get(uuid)
@@clusters[uuid]
end
def list
@@clusters
end
end
end