uniqid 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7daa5d8f85a6e7ef653927d0291655f422bd02d9ce32dfa5feb4089b0f2e9aa
4
+ data.tar.gz: e72eb3d98b61f160c397ee88e09a13d8cda11b77b0534043cd9b4412d92d8e3e
5
+ SHA512:
6
+ metadata.gz: c287c124ecff1f3e99bef3cca2e2da52878e4b0fa4c5717f9d7ad5ab76884920fcf83bf07eb998a7fc950dbcb6adc47ca0dc21677bcc55defea824196f15e38c
7
+ data.tar.gz: 685b6b0137c3d3ca76596b3ed3279c3c3a5b0d3f78b46b4bd26dda47013fcb0cfafd87028bc277d5c73a23a300eeca3dafd67240aadde8d4e19d4ed265542382
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
File without changes
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.5.5" project-jdk-type="RUBY_SDK" />
4
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/uniqid.iml" filepath="$PROJECT_DIR$/.idea/uniqid.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,64 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="actioncable (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="actionmailbox (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="actionmailer (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="actionpack (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="actiontext (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="actionview (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="activejob (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="activemodel (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="activerecord (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="activestorage (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.5.5) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.5.5) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.7, RVM: ruby-2.5.5) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="crass (v1.0.6, RVM: ruby-2.5.5) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, RVM: ruby-2.5.5) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="erubi (v1.10.0, RVM: ruby-2.5.5) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="globalid (v0.4.2, RVM: ruby-2.5.5) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.5, RVM: ruby-2.5.5) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="loofah (v2.7.0, RVM: ruby-2.5.5) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="mail (v2.7.1, RVM: ruby-2.5.5) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="marcel (v0.3.3, RVM: ruby-2.5.5) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, RVM: ruby-2.5.5) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="mimemagic (v0.3.5, RVM: ruby-2.5.5) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="mini_mime (v1.0.2, RVM: ruby-2.5.5) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.4.0, RVM: ruby-2.5.5) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.2, RVM: ruby-2.5.5) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="nio4r (v2.5.4, RVM: ruby-2.5.5) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.10.10, RVM: ruby-2.5.5) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, RVM: ruby-2.5.5) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, RVM: ruby-2.5.5) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="rails (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, RVM: ruby-2.5.5) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.3.0, RVM: ruby-2.5.5) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="railties (v6.0.3.4, RVM: ruby-2.5.5) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.1, RVM: ruby-2.5.5) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, RVM: ruby-2.5.5) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.0, RVM: ruby-2.5.5) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.0, RVM: ruby-2.5.5) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.0, RVM: ruby-2.5.5) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.0, RVM: ruby-2.5.5) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="sprockets (v4.0.2, RVM: ruby-2.5.5) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="sprockets-rails (v3.2.2, RVM: ruby-2.5.5) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="thor (v1.0.1, RVM: ruby-2.5.5) [gem]" level="application" />
58
+ <orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, RVM: ruby-2.5.5) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.8, RVM: ruby-2.5.5) [gem]" level="application" />
60
+ <orderEntry type="library" scope="PROVIDED" name="websocket-driver (v0.7.3, RVM: ruby-2.5.5) [gem]" level="application" />
61
+ <orderEntry type="library" scope="PROVIDED" name="websocket-extensions (v0.1.5, RVM: ruby-2.5.5) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.4.1, RVM: ruby-2.5.5) [gem]" level="application" />
63
+ </component>
64
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,56 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <list default="true" id="43667bc4-9c7c-4db9-848d-a167a35b61be" name="Default Changelist" comment="" />
5
+ <option name="SHOW_DIALOG" value="false" />
6
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
7
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
8
+ <option name="LAST_RESOLUTION" value="IGNORE" />
9
+ </component>
10
+ <component name="Git.Settings">
11
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
12
+ </component>
13
+ <component name="ProjectId" id="1kgWujCEFc42bPgS7P96FW6cg7p" />
14
+ <component name="ProjectViewState">
15
+ <option name="hideEmptyMiddlePackages" value="true" />
16
+ <option name="showLibraryContents" value="true" />
17
+ </component>
18
+ <component name="PropertiesComponent">
19
+ <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
20
+ <property name="WebServerToolWindowFactoryState" value="false" />
21
+ <property name="last_opened_file_path" value="$PROJECT_DIR$/../snow_flake-0.1.1" />
22
+ <property name="node.js.detected.package.eslint" value="true" />
23
+ <property name="node.js.detected.package.tslint" value="true" />
24
+ <property name="node.js.path.for.package.eslint" value="project" />
25
+ <property name="node.js.path.for.package.tslint" value="project" />
26
+ <property name="node.js.selected.package.eslint" value="(autodetect)" />
27
+ <property name="node.js.selected.package.tslint" value="(autodetect)" />
28
+ </component>
29
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
30
+ <component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
31
+ <component name="TaskManager">
32
+ <task active="true" id="Default" summary="Default task">
33
+ <changelist id="43667bc4-9c7c-4db9-848d-a167a35b61be" name="Default Changelist" comment="" />
34
+ <created>1606122939802</created>
35
+ <option name="number" value="Default" />
36
+ <option name="presentableId" value="Default" />
37
+ <updated>1606122939802</updated>
38
+ <workItem from="1606122940871" duration="3447000" />
39
+ <workItem from="1606187010808" duration="7000" />
40
+ </task>
41
+ <servers />
42
+ </component>
43
+ <component name="TypeScriptGeneratedFilesManager">
44
+ <option name="version" value="3" />
45
+ </component>
46
+ <component name="WindowStateProjectService">
47
+ <state x="427" y="310" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1606180372498">
48
+ <screen x="0" y="0" width="1844" height="1080" />
49
+ </state>
50
+ <state x="427" y="310" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1844.1080@0.0.1844.1080" timestamp="1606180372497" />
51
+ <state x="648" y="231" key="FileChooserDialogImpl" timestamp="1606129359872">
52
+ <screen x="0" y="0" width="1844" height="1080" />
53
+ </state>
54
+ <state x="648" y="231" key="FileChooserDialogImpl/0.0.1844.1080@0.0.1844.1080" timestamp="1606129359872" />
55
+ </component>
56
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at zhangcy.cn@outlook.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in uniqid.gemspec
6
+ gemspec
@@ -0,0 +1,158 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ uniqid (0.1.1)
5
+ rails
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.0.3.4)
11
+ actionpack (= 6.0.3.4)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.0.3.4)
15
+ actionpack (= 6.0.3.4)
16
+ activejob (= 6.0.3.4)
17
+ activerecord (= 6.0.3.4)
18
+ activestorage (= 6.0.3.4)
19
+ activesupport (= 6.0.3.4)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.0.3.4)
22
+ actionpack (= 6.0.3.4)
23
+ actionview (= 6.0.3.4)
24
+ activejob (= 6.0.3.4)
25
+ mail (~> 2.5, >= 2.5.4)
26
+ rails-dom-testing (~> 2.0)
27
+ actionpack (6.0.3.4)
28
+ actionview (= 6.0.3.4)
29
+ activesupport (= 6.0.3.4)
30
+ rack (~> 2.0, >= 2.0.8)
31
+ rack-test (>= 0.6.3)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
+ actiontext (6.0.3.4)
35
+ actionpack (= 6.0.3.4)
36
+ activerecord (= 6.0.3.4)
37
+ activestorage (= 6.0.3.4)
38
+ activesupport (= 6.0.3.4)
39
+ nokogiri (>= 1.8.5)
40
+ actionview (6.0.3.4)
41
+ activesupport (= 6.0.3.4)
42
+ builder (~> 3.1)
43
+ erubi (~> 1.4)
44
+ rails-dom-testing (~> 2.0)
45
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
+ activejob (6.0.3.4)
47
+ activesupport (= 6.0.3.4)
48
+ globalid (>= 0.3.6)
49
+ activemodel (6.0.3.4)
50
+ activesupport (= 6.0.3.4)
51
+ activerecord (6.0.3.4)
52
+ activemodel (= 6.0.3.4)
53
+ activesupport (= 6.0.3.4)
54
+ activestorage (6.0.3.4)
55
+ actionpack (= 6.0.3.4)
56
+ activejob (= 6.0.3.4)
57
+ activerecord (= 6.0.3.4)
58
+ marcel (~> 0.3.1)
59
+ activesupport (6.0.3.4)
60
+ concurrent-ruby (~> 1.0, >= 1.0.2)
61
+ i18n (>= 0.7, < 2)
62
+ minitest (~> 5.1)
63
+ tzinfo (~> 1.1)
64
+ zeitwerk (~> 2.2, >= 2.2.2)
65
+ builder (3.2.4)
66
+ concurrent-ruby (1.1.7)
67
+ crass (1.0.6)
68
+ diff-lcs (1.4.4)
69
+ erubi (1.10.0)
70
+ globalid (0.4.2)
71
+ activesupport (>= 4.2.0)
72
+ i18n (1.8.5)
73
+ concurrent-ruby (~> 1.0)
74
+ loofah (2.7.0)
75
+ crass (~> 1.0.2)
76
+ nokogiri (>= 1.5.9)
77
+ mail (2.7.1)
78
+ mini_mime (>= 0.1.1)
79
+ marcel (0.3.3)
80
+ mimemagic (~> 0.3.2)
81
+ method_source (1.0.0)
82
+ mimemagic (0.3.5)
83
+ mini_mime (1.0.2)
84
+ mini_portile2 (2.4.0)
85
+ minitest (5.14.2)
86
+ nio4r (2.5.4)
87
+ nokogiri (1.10.10)
88
+ mini_portile2 (~> 2.4.0)
89
+ rack (2.2.3)
90
+ rack-test (1.1.0)
91
+ rack (>= 1.0, < 3)
92
+ rails (6.0.3.4)
93
+ actioncable (= 6.0.3.4)
94
+ actionmailbox (= 6.0.3.4)
95
+ actionmailer (= 6.0.3.4)
96
+ actionpack (= 6.0.3.4)
97
+ actiontext (= 6.0.3.4)
98
+ actionview (= 6.0.3.4)
99
+ activejob (= 6.0.3.4)
100
+ activemodel (= 6.0.3.4)
101
+ activerecord (= 6.0.3.4)
102
+ activestorage (= 6.0.3.4)
103
+ activesupport (= 6.0.3.4)
104
+ bundler (>= 1.3.0)
105
+ railties (= 6.0.3.4)
106
+ sprockets-rails (>= 2.0.0)
107
+ rails-dom-testing (2.0.3)
108
+ activesupport (>= 4.2.0)
109
+ nokogiri (>= 1.6)
110
+ rails-html-sanitizer (1.3.0)
111
+ loofah (~> 2.3)
112
+ railties (6.0.3.4)
113
+ actionpack (= 6.0.3.4)
114
+ activesupport (= 6.0.3.4)
115
+ method_source
116
+ rake (>= 0.8.7)
117
+ thor (>= 0.20.3, < 2.0)
118
+ rake (12.3.3)
119
+ rspec (3.10.0)
120
+ rspec-core (~> 3.10.0)
121
+ rspec-expectations (~> 3.10.0)
122
+ rspec-mocks (~> 3.10.0)
123
+ rspec-core (3.10.0)
124
+ rspec-support (~> 3.10.0)
125
+ rspec-expectations (3.10.0)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.10.0)
128
+ rspec-mocks (3.10.0)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.10.0)
131
+ rspec-support (3.10.0)
132
+ sprockets (4.0.2)
133
+ concurrent-ruby (~> 1.0)
134
+ rack (> 1, < 3)
135
+ sprockets-rails (3.2.2)
136
+ actionpack (>= 4.0)
137
+ activesupport (>= 4.0)
138
+ sprockets (>= 3.0.0)
139
+ thor (1.0.1)
140
+ thread_safe (0.3.6)
141
+ tzinfo (1.2.8)
142
+ thread_safe (~> 0.1)
143
+ websocket-driver (0.7.3)
144
+ websocket-extensions (>= 0.1.0)
145
+ websocket-extensions (0.1.5)
146
+ zeitwerk (2.4.1)
147
+
148
+ PLATFORMS
149
+ ruby
150
+
151
+ DEPENDENCIES
152
+ bundler
153
+ rake
154
+ rspec
155
+ uniqid!
156
+
157
+ BUNDLED WITH
158
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 ChanKerwin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Uniqid
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/uniqid`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'uniqid'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install uniqid
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/uniqid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/uniqid/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Uniqid project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/uniqid/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "uniqid"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uniqid/version'
4
+
5
+ # ID uniform generation rules, using SnowFlake algorithm, composed of 64 bits
6
+ # | 40 bits: Timestamp (millisecond) | 9 bits: WORKER_ID | 6 bits: SERVER_ID | 2 bits: reserved | 7 bits: serial number|
7
+ # VERSION = 1.0.0, Release: 2018-03-08
8
+ # Usage:
9
+ # Gemfile => gem 'uniqid'
10
+ # Commandline => $ bundle install
11
+ # ApplicationRecord => include Uniqid
12
+ # before the object of model being created => UniqID.generate(worker_id, server_id)
13
+ module Uniqid
14
+ class Error < StandardError; end
15
+
16
+ def self.included(klass)
17
+ klass.extend ClassMethods
18
+ end
19
+
20
+ # @params worker_id
21
+ # @params server_id
22
+ module ClassMethods
23
+ # 64 bits
24
+ TOTAL_LEN = 64
25
+
26
+ # 40 bits for time in milliseconds
27
+ TIMESTAMP_LEN = 40
28
+
29
+ # Start timestamp, 2018-01-01 00:00:00
30
+ TIMESTAMP_START = 1_514_736_000_000
31
+ MAX_TIMESTAMP = -1 ^ (-1 << TIMESTAMP_LEN)
32
+
33
+ # 9 bits for worker ID, (0-511)
34
+ WORKER_ID_LEN = 9
35
+ # The maximum number of workers supported, -1:complement0b111111111
36
+ MAX_WORKER_NUM = -1 ^ (-1 << WORKER_ID_LEN)
37
+
38
+ # 6 bits for server ID, (0-63)
39
+ SERVER_ID_LEN = 6
40
+ # The maximum number of servers supported, result is 63
41
+ MAX_SERVER_NUM = -1 ^ (-1 << SERVER_ID_LEN)
42
+
43
+ # 2 bits reserved, (0-3)
44
+ BAK_ID_LEN = 2
45
+ MAX_BAK_NUM = -1 ^ (-1 << BAK_ID_LEN)
46
+
47
+ # 7 bits for serial number in milliseconds, (0-127)
48
+ LOCAL_ID_LEN = 7
49
+ MAX_LOCAL_NUM = -1 ^ (-1 << LOCAL_ID_LEN)
50
+
51
+ @last_timestamp = -1 # Save the last timestamp
52
+ @sequence = 0 # Initial value of serial number
53
+
54
+ # Prevent the generation time is smaller than the previous time(due to issues such as NTP callback),
55
+ # and keep the incremental trend.
56
+ def next_timestamp(last_timestamp)
57
+ timestamp = (Time.now.to_f * 1000).to_i
58
+ timestamp = (Time.now.to_f * 1000).to_i while timestamp <= last_timestamp
59
+ timestamp
60
+ end
61
+
62
+ # @return worker_id[int] 64 bits
63
+ def worker_value(value)
64
+ # Handling parameter exception
65
+ value = 0 if value.to_i > MAX_WORKER_NUM || value.to_i.negative?
66
+
67
+ value.to_i << SERVER_ID_LEN + BAK_ID_LEN + LOCAL_ID_LEN # 15 bits left
68
+ end
69
+
70
+ def server_value(value)
71
+ left_num = BAK_ID_LEN + LOCAL_ID_LEN
72
+
73
+ value = 0 if value.to_i > MAX_SERVER_NUM || value.to_i.negative?
74
+
75
+ unless value.present?
76
+ # In development mode, take the random number of the largest supported number
77
+ if Rails.env == 'development'
78
+ rand(MAX_SERVER_NUM) << left_num
79
+ else
80
+ value = 0
81
+ end
82
+ end
83
+
84
+ value.to_i << left_num
85
+ end
86
+
87
+ # Generate ID
88
+ def generate(worker_value, server_value, timestamp = nil)
89
+ server_value = server_value(server_value)
90
+ worker_value = worker_value(worker_value)
91
+
92
+ # The reserved position is temporarily random, shifted by 7 bits to the left
93
+ bak_value = (rand(MAX_BAK_NUM) << LOCAL_ID_LEN)
94
+
95
+ local_timestamp =
96
+ if timestamp
97
+ (timestamp * 1000).to_i
98
+ else
99
+ (Time.now.to_f * 1000).to_i
100
+ end
101
+
102
+ # If the last generation time is the same as the current time, the sequence within milliseconds
103
+ if local_timestamp == @last_timestamp
104
+
105
+ # The sequence is self-increasing and only has 7 bits,
106
+ # so it is ANDed with MAX_LOCAL_NUM and removes the high bits
107
+ sequence = (@sequence + 1) & MAX_LOCAL_NUM
108
+
109
+ # Check for overflow: whether the sequence exceeds 127 per millisecond,
110
+ # when 127, it is equal to 0 after AND with MAX_LOCAL_NUM
111
+ if sequence.zero?
112
+ # Wait until the next millisecond
113
+ local_timestamp = next_timestamp(@last_timestamp)
114
+ end
115
+
116
+ else
117
+ # If it is different from the last generation time, reset the sequence
118
+ # In order to ensure that the mantissa is more random, set a random number in the last digit
119
+ @sequence = rand(1 << LOCAL_ID_LEN)
120
+ sequence = @sequence
121
+ end
122
+
123
+ @last_timestamp = local_timestamp
124
+
125
+ # Save the difference of timestamp(current timestamp - start timestamp)
126
+ local_timestamp -= TIMESTAMP_START
127
+
128
+ (local_timestamp << (TOTAL_LEN - TIMESTAMP_LEN)) | server_value | worker_value | bak_value | sequence
129
+ end
130
+
131
+ # Reverse check timestamp
132
+ def get_timestamp(id)
133
+ timestamp = (id >> (TOTAL_LEN - TIMESTAMP_LEN)) / 1000.0
134
+ Time.at(timestamp + TIMESTAMP_START / 1000.0)
135
+ end
136
+ end
137
+ end
138
+
139
+ # To inherit from ActiveRecord::Base and encapsulate into class for easy calling in Model
140
+ class UniqID < ActiveRecord::Base
141
+ include Uniqid
142
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uniqid
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/uniqid/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'uniqid'
5
+ spec.version = Uniqid::VERSION
6
+ spec.authors = ['ChanKerwin']
7
+ spec.email = ['zhangcy.cn@outlook.com']
8
+
9
+ spec.summary = 'Unique ID Generator.'
10
+ spec.description = "A distributed unique ID generator inspired by Twitter's Snowflake."
11
+ spec.homepage = 'https://github.com/ChanKerwin/uniqid'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rails'
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uniqid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - ChanKerwin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A distributed unique ID generator inspired by Twitter's Snowflake.
70
+ email:
71
+ - zhangcy.cn@outlook.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".idea/.gitignore"
78
+ - ".idea/misc.xml"
79
+ - ".idea/modules.xml"
80
+ - ".idea/uniqid.iml"
81
+ - ".idea/vcs.xml"
82
+ - ".idea/workspace.xml"
83
+ - ".rspec"
84
+ - ".travis.yml"
85
+ - CODE_OF_CONDUCT.md
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - lib/uniqid.rb
94
+ - lib/uniqid/version.rb
95
+ - uniqid.gemspec
96
+ homepage: https://github.com/ChanKerwin/uniqid
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Unique ID Generator.
119
+ test_files: []