uniqable 0.1.1 → 0.1.2

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: 9c62d651fd862f7f16f28da78984646b6f058a3a
4
- data.tar.gz: 22ed697e5d197cc2ec2cd51ace98d8cd222b6d59
3
+ metadata.gz: ebeb80c142eafe8ded76be2dad828980e5f6e17a
4
+ data.tar.gz: d7da8ec249afd915d8b1c7e30f44bef610428c88
5
5
  SHA512:
6
- metadata.gz: 02aea5d916ad5f4a834847f1daf4ce3dcbd678f7e117695465df991c2f33c05df5881c75e4969156d9dadfbb88a4e172bc478c68da6186fc05d4c6ca66af9fb1
7
- data.tar.gz: aac1283ae40d4095ce7408edcf7de102e8bad63dda1ea096ee8819ee17a24b782da18a91ea38a386c0f3dda928eb4afc68b2f3d5520e90bd1221a4defcc9be8f
6
+ metadata.gz: 4d18f0badffd54ff6cc4347e2e431851830ef78066792802244bed138ccab1169a5223137562cf2d1c520aa270949c74b48fe7d6f97aeded123dbe19b6569118
7
+ data.tar.gz: 3ad77d0b1cab20e176f89896c44258ed8eb9f3f1aac8fbe86e93768eb5b61ef30371f5fd7cfe32358558797be71191cb9e6d958a73e6c73af35d34825d61599a
data/.circleci/config.yml CHANGED
@@ -25,6 +25,10 @@ jobs:
25
25
  - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
26
  # fallback to using the latest cache if no exact match is found
27
27
  - v1-dependencies-
28
+ - run:
29
+ name: install bundler
30
+ command: |
31
+ gem install bundler --pre
28
32
 
29
33
  - run:
30
34
  name: install dependencies
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ uniqable
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uniqable (0.1.0)
4
+ uniqable (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -35,20 +35,27 @@ It generates unique and random token before each Model instance is created.
35
35
 
36
36
  if you want you can use `:to_param` option to generate automatically `#to_param` method
37
37
  ```ruby
38
- uniqable :uid, :slug, to_param: :uid
38
+ uniqable :uid, :slug, to_param: :uid
39
39
  ```
40
40
 
41
41
  anyway you have one more method `.find_uniqable` which one you can use to find your model record
42
42
  ```ruby
43
43
  MyModel.find_uniqable params[:uid]
44
44
  ```
45
+ and another one is `.uniqable_fields`
46
+ ```ruby
47
+ MyModel.uniqable_fields
48
+ ```
45
49
 
46
50
  You can also create your own token callback method and set the field:
47
51
 
48
52
  ```ruby
49
- def uniqable_uid(field)
50
- self[field] = 100_000 + rand(999_999)
51
- end
53
+ class MyModel
54
+ ...
55
+ def uniqable_uid(field)
56
+ self[field] = 100_000 + rand(999_999)
57
+ end
58
+ end
52
59
  ```
53
60
 
54
61
  ## Development
data/lib/uniqable.rb CHANGED
@@ -14,12 +14,14 @@ module Uniqable
14
14
  # uniqable :uid, :slug, to_param: :uid
15
15
  def uniqable(*fields, to_param: nil)
16
16
  fields = [:uid] if fields.blank?
17
- @_uniqable_fields = fields
18
17
  fields.each do |name|
19
18
  before_create { |record| record.uniqable_uid(name) }
20
19
  end
21
- # :to_param option
22
- if to_param
20
+ define_singleton_method :uniqable_fields do
21
+ fields
22
+ end
23
+
24
+ if to_param # :to_param option
23
25
  define_method :to_param do
24
26
  public_send(to_param)
25
27
  end
@@ -33,7 +35,7 @@ module Uniqable
33
35
  # MyModel.find_uniqable params[:uid] # can be uid or slug column
34
36
  # @return [self]
35
37
  def find_uniqable(uid)
36
- where_sql = @_uniqable_fields.map{ |r| "#{table_name}.#{r} = :uid"}.join(' OR ')
38
+ where_sql = uniqable_fields.map{ |r| "#{table_name}.#{r} = :uid"}.join(' OR ')
37
39
  self.where(where_sql, uid: uid).take(1)
38
40
  end
39
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uniqable
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
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.1.1
4
+ version: 0.1.2
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-07 00:00:00.000000000 Z
11
+ date: 2018-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -92,6 +92,7 @@ files:
92
92
  - ".rspec"
93
93
  - ".rubocop.yml"
94
94
  - ".ruby-gems"
95
+ - ".ruby-gemset"
95
96
  - ".ruby-version"
96
97
  - ".travis.yml"
97
98
  - Gemfile