prettyid 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1b67ccbe04d5c451bc19bf075ab339ea2e9ad37c343e07e502731d4c493f9c8
4
- data.tar.gz: dec40ffab0f1547b8c4b4feda8565cedbc38413fab8c4eadd21044a2f6bd385c
3
+ metadata.gz: 8e233caf6a19fbefeec6b43ee0a7f70d9d1959ad9398b234d2c0a2f35ed7c929
4
+ data.tar.gz: 13ee1ba7b83f2b297f0ebb61523fa32a97e82ae90a985f789b8c04a2f4007889
5
5
  SHA512:
6
- metadata.gz: 9ed263be9a2feb3158ea0f18890401e9b3054cc3c2bb2980ba81bfd14312270241e56170372cec3ddf0d422631054a57d200d377cd1ace66e746cec2d905c1b6
7
- data.tar.gz: 6b0116bc40e0e6187c3b6ae21d120e6d1079627f373099e0e38ca1db95ea5ae38c420e69b86d78baa822992028f3f67e8f42e6c40764d23fddab5fce9b4ceb0c
6
+ metadata.gz: a87882d799c08c36ca46bc9e57194a562a96b08d8b45e92c8301bab72529481d65d6ccaf2c4b0c31a615ef3e5862b14c91902d4ef8f86285cdbdd02fa0541a76
7
+ data.tar.gz: b6f8fe2287aabfcdfee7788bedb8a239f88a4921f7b6891e83c3d1d9e4d68d38b0a546f39ee937073e5c90f8302ab65d97ece601c64eaab87aba2cff93458dc4
@@ -1,5 +1,4 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.3
5
- before_install: gem install bundler -v 1.16.1
4
+ - 2.6.5
@@ -1,31 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prettyid (0.1.2)
4
+ prettyid (0.2.0)
5
5
  activerecord (>= 4.2.0)
6
6
  activesupport (>= 4.2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.2.0)
12
- activesupport (= 5.2.0)
13
- activerecord (5.2.0)
14
- activemodel (= 5.2.0)
15
- activesupport (= 5.2.0)
16
- arel (>= 9.0)
17
- activesupport (5.2.0)
11
+ activemodel (6.0.2.1)
12
+ activesupport (= 6.0.2.1)
13
+ activerecord (6.0.2.1)
14
+ activemodel (= 6.0.2.1)
15
+ activesupport (= 6.0.2.1)
16
+ activesupport (6.0.2.1)
18
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
18
  i18n (>= 0.7, < 2)
20
19
  minitest (~> 5.1)
21
20
  tzinfo (~> 1.1)
22
- arel (9.0.0)
23
- concurrent-ruby (1.0.5)
21
+ zeitwerk (~> 2.2)
22
+ concurrent-ruby (1.1.6)
24
23
  diff-lcs (1.3)
25
- i18n (1.0.1)
24
+ i18n (1.8.2)
26
25
  concurrent-ruby (~> 1.0)
27
- minitest (5.11.3)
28
- rake (12.3.1)
26
+ minitest (5.14.0)
27
+ rake (13.0.1)
29
28
  rspec (3.7.0)
30
29
  rspec-core (~> 3.7.0)
31
30
  rspec-expectations (~> 3.7.0)
@@ -39,10 +38,11 @@ GEM
39
38
  diff-lcs (>= 1.2.0, < 2.0)
40
39
  rspec-support (~> 3.7.0)
41
40
  rspec-support (3.7.1)
42
- sqlite3 (1.3.13)
41
+ sqlite3 (1.4.2)
43
42
  thread_safe (0.3.6)
44
- tzinfo (1.2.5)
43
+ tzinfo (1.2.6)
45
44
  thread_safe (~> 0.1)
45
+ zeitwerk (2.3.0)
46
46
 
47
47
  PLATFORMS
48
48
  ruby
@@ -52,7 +52,7 @@ DEPENDENCIES
52
52
  prettyid!
53
53
  rake
54
54
  rspec
55
- sqlite3
55
+ sqlite3 (>= 1.4.2)
56
56
 
57
57
  BUNDLED WITH
58
- 1.16.1
58
+ 1.17.3
data/README.md CHANGED
@@ -71,6 +71,19 @@ account.save
71
71
  account.id #=> acc_test_....
72
72
  ```
73
73
 
74
+ For cases when you don't want underscore (_) to be in id you can set it to nil:
75
+
76
+ ```
77
+ class User < ActiveRecord::Base
78
+ include PrettyId
79
+
80
+ self.id_prefix = 'usr'
81
+ self.id_separator = nil
82
+ end
83
+
84
+ user.id #=> usrPZUjZiIF3bnZ
85
+ ```
86
+
74
87
  ## Installation
75
88
 
76
89
  **Note** There is another gem called 'pretty_id' so I had to rename mine into prettyid. So, be careful when you install gem and require it. It's a kind'a trick you do with 'activerecord' as well ;)
@@ -91,7 +104,7 @@ Or install it yourself as:
91
104
 
92
105
 
93
106
 
94
- ## Perfomance
107
+ ## Performance
95
108
 
96
109
  If you care about performance, it's better to measure it yourself :) I have measured method that generates id (```rake bm```). Here are results for 1M calls:
97
110
 
@@ -10,6 +10,8 @@ module PrettyId
10
10
  def self.primary_key
11
11
  'id'
12
12
  end
13
+
14
+ self.id_separator = '_'
13
15
  end
14
16
 
15
17
  class_methods do
@@ -20,6 +22,14 @@ module PrettyId
20
22
  def id_prefix
21
23
  @id_prefix || name.downcase[0, 3]
22
24
  end
25
+
26
+ def id_separator=(separator)
27
+ @id_separator = separator
28
+ end
29
+
30
+ def id_separator
31
+ @id_separator
32
+ end
23
33
  end
24
34
 
25
35
  def _create_record(*)
@@ -7,7 +7,7 @@ module PrettyId
7
7
  end
8
8
 
9
9
  def id
10
- "#{prefix}_#{SecRandom.alphanumeric(length)}"
10
+ "#{prefix}#{separator}#{SecRandom.alphanumeric(length)}"
11
11
  end
12
12
 
13
13
  def length
@@ -21,5 +21,9 @@ module PrettyId
21
21
  record.class.id_prefix
22
22
  end
23
23
  end
24
+
25
+ def separator
26
+ record.class.id_separator
27
+ end
24
28
  end
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module PrettyId
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "sqlite3"
26
+ spec.add_development_dependency "sqlite3", ">= 1.4.2"
27
27
 
28
28
  spec.add_dependency "activerecord", ">= 4.2.0"
29
29
  spec.add_dependency "activesupport", ">= 4.2.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prettyid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Gabriel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-28 00:00:00.000000000 Z
11
+ date: 2020-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.4.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.4.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.7.5
138
+ rubygems_version: 3.0.8
140
139
  signing_key:
141
140
  specification_version: 4
142
141
  summary: Generate Stripe-like ids for your ActiveRecord models