uniqable 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 614ad5000574685a9eae9222e26c04898a03b22e
4
- data.tar.gz: ff0f29efadbf39c75d7b2340af4a3cf628fc3e78
3
+ metadata.gz: 4114db480c0e9252f47842d2b146924b7e5e1f83
4
+ data.tar.gz: 0b4f10b5940dfcb66d7c636cce0b5dd0a7fa7f20
5
5
  SHA512:
6
- metadata.gz: ae466818b9f47c24b1a9a0d5359f37cbde6e189a6ac602c72204d585778323b75a32b02ffa97bbca00ec20f08f8ea7c1284936463043659801ec45dd832a38e0
7
- data.tar.gz: c34d784116d1c532248f3aed6884a4ddc5cd8008f2fe2d08ce81f8ce67c3ec93c800fc963ff7b452d635c0ab34521878be3cf12b0e7c477304a1c2fa01d586ef
6
+ metadata.gz: 261020540cb88c7799eca3add448c1628245e4f02af17c7f5516cdf58224cf57574111f334db84b767ecdb9be36780df99f8587253f48acaf6b32fd153ef3ca9
7
+ data.tar.gz: b35eb3bdbb3bfa4f2b66ec45775ee46cb7be44fd736ccb2ba957e7ff8d85bfbc5e96533a8173d171c42628bd1514ad4280e54a640aa97d86fe897a8d588a3eea
@@ -7,7 +7,7 @@ jobs:
7
7
  build:
8
8
  docker:
9
9
  # specify the version you desire here
10
- - image: circleci/ruby:2.4.1-node-browsers
10
+ - image: circleci/ruby:2.3-node-browsers
11
11
 
12
12
  # Specify service dependencies here if necessary
13
13
  # CircleCI maintains a library of pre-built images
@@ -18,6 +18,10 @@ jobs:
18
18
 
19
19
  steps:
20
20
  - checkout
21
+ - run:
22
+ name: install sqlite
23
+ command: |
24
+ sudo apt-get install sqlite3
21
25
 
22
26
  # Download and cache dependencies
23
27
  - restore_cache:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uniqable (0.1.3)
4
+ uniqable (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -79,4 +79,4 @@ DEPENDENCIES
79
79
  uniqable!
80
80
 
81
81
  BUNDLED WITH
82
- 1.16.2
82
+ 1.16.3
data/README.md CHANGED
@@ -42,7 +42,11 @@ anyway you have one more method `.find_uniqable` which one you can use to find y
42
42
  ```ruby
43
43
  MyModel.find_uniqable params[:uid]
44
44
  # or
45
- MyModel.find_uniqable! params[:uid] # this will raise exception ActiveRecord::RecordNotFound if record is absent
45
+ MyModel.find_uniqable! params[:uid] # this will raise exception ActiveRecord::RecordNotFound if record is absent
46
+ # or you can use numerical ID same time and Uniqable will detect it and tries to find by primary key (as regular id)
47
+ MyModel.find_uniqable params[:id]
48
+ # or
49
+ MyModel.find_uniqable! params[:id]
46
50
  ```
47
51
  and another one is `.uniqable_fields`
48
52
  ```ruby
@@ -32,7 +32,9 @@ module Uniqable
32
32
 
33
33
  # @return [self]
34
34
  def where_uniqable(uid)
35
- where_sql = uniqable_fields.map { |r| "#{table_name}.#{r} = :uid" }.join(' OR ')
35
+ where_sql = key_uid?(uid) ?
36
+ uniqable_fields.map { |r| "#{table_name}.#{r} = :uid" }.join(' OR ') :
37
+ "#{self.primary_key} = :uid"
36
38
  where(where_sql, uid: uid)
37
39
  end
38
40
 
@@ -51,14 +53,21 @@ module Uniqable
51
53
  def find_uniqable!(uid)
52
54
  where_uniqable(uid).take!
53
55
  end
56
+
57
+ private
58
+
59
+ def key_uid?(uid)
60
+ uid.to_s =~ /\D+/
61
+ end
54
62
  end
55
63
 
56
64
  # Generate and set random and uniq field
57
65
  # @TODO: split into 2 actions generate and set
58
66
  def uniqable_uid(field)
59
67
  loop do
60
- send("#{field}=", SecureRandom.hex(8))
61
- break unless self.class.where(field => send(field.to_sym)).exists?
68
+ uniq_code = SecureRandom.hex(8)
69
+ send("#{field}=", uniq_code)
70
+ break unless self.class.where(field => uniq_code).exists?
62
71
  end
63
72
  end
64
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uniqable
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uniqable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renat "MpaK" Ibragimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-12 00:00:00.000000000 Z
11
+ date: 2018-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.6.10
155
+ rubygems_version: 2.6.11
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Uniqable - uniq and random token for ActiveRecord models