Initial commit

This commit is contained in:
Yaser
2026-08-13 19:50:53 +03:30
commit 38084458fe
879 changed files with 95198 additions and 0 deletions

31
lib/peatio/uuid.rb Normal file
View File

@@ -0,0 +1,31 @@
class UUID
class << self
def generate
SecureRandom.uuid
end
def validate(uuid)
uuid.match?(/\A[\da-f]{32}\z/i) || uuid.match?(/\A(urn:uuid:)?[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i)
end
end
class Type < ActiveRecord::Type::Value
def deserialize(value)
return if value.nil?
value.unpack('H*').first.tap do |str|
[20, 16, 12, 8].each { |pos| str.insert(pos, '-') }
end
end
def serialize(value)
[ value.delete('-') ].pack('H*')
end
def quoted_id(value)
return if value.nil?
"x'#{value.unpack('H*').first}'"
end
end
end