Files
ubicloud/model/object_metatag.rb
Jeremy Evans 3e448476be Inline the filter_authorize_dataset method logic
This is simpler and the removal of indirection makes it easier to
reason about.
2025-01-17 12:47:51 -08:00

37 lines
755 B
Ruby

# frozen_string_literal: true
require_relative "object_tag"
require "delegate"
class ObjectMetatag < DelegateClass(ObjectTag)
def self.to_meta(ubid)
ubid.sub(/\At0/, "t2")
end
def self.from_meta(ubid)
ubid.sub(/\At2/, "t0")
end
def self.from_meta_uuid(uuid)
UBID.to_uuid(from_meta(UBID.from_uuidish(uuid).to_s))
end
def self.to_meta_uuid(uuid)
UBID.to_uuid(to_meta(UBID.from_uuidish(uuid).to_s))
end
# Designed solely for use with UBID.resolve_map
def self.where(id:)
ObjectTag.where(id: id.map { from_meta_uuid(_1) }).map(&:metatag)
end
# Designed solely for use with UBID.decode
def self.[](id)
ObjectTag[from_meta_uuid(id)]&.metatag
end
def id = metatag_uuid
def ubid = metatag_ubid
end