-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from appwrite/dev
Fix msg91 params
- Loading branch information
Showing
7 changed files
with
36 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
require 'securerandom' | ||
|
||
module Appwrite | ||
class ID | ||
def self.custom(id) | ||
id | ||
end | ||
|
||
def self.unique | ||
'unique()' | ||
|
||
# Generate a unique ID with padding to have a longer ID | ||
def self.unique(padding=7) | ||
base_id = self.hex_timestamp | ||
random_padding = SecureRandom.hex(padding) | ||
random_padding = random_padding[0...padding] | ||
base_id + random_padding | ||
end | ||
|
||
#Generate an hex ID based on timestamp | ||
#Recreated from https://www.php.net/manual/en/function.uniqid.php | ||
private_class_method def self.hex_timestamp | ||
now = Time.now | ||
sec = now.to_i | ||
usec = now.usec | ||
hex_timestamp = "%08x%05x" % [sec, usec] | ||
hex_timestamp | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters