randomid 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.README.md.swp +0 -0
- data/README.md +29 -0
- data/lib/generators/randomid_generator.rb +13 -0
- data/lib/randomid/model_additions.rb +0 -3
- data/lib/randomid/version.rb +1 -1
- data/randomid-0.1.1.gem +0 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f8b8d5cdc82b1575d85d0256d1804c108e9583a
|
4
|
+
data.tar.gz: ae014ad5fb7d4b76f6a90fb01008fa9d628de1cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40fa662e5ab49ba8f60dca40230747d75c52147585680c4c06f80bec01d5b46d4733bade3bbba7f2ee915a9382d050aab7385ca32c3ca6c45a6017a1f9838d32
|
7
|
+
data.tar.gz: 0690165c4972e085fbe832946a4fc2b9ffc49cd4aede9045b3f0c68bef22b9d705a5d5857f9bda7474101112d79b6e5336abd25ca127e9b4cdcef6899110508b
|
data/.README.md.swp
ADDED
Binary file
|
data/README.md
CHANGED
@@ -28,11 +28,40 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
+
**Short Method**
|
32
|
+
|
33
|
+
Simply run this generator to add the necessary migration and alterations to the model:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
rails generate randomid model_name attribute_name token_length
|
37
|
+
```
|
38
|
+
|
39
|
+
Where
|
40
|
+
|
41
|
+
* model_name = *singular version of the model* e.g. customers model would mean you put 'customer'
|
42
|
+
* attribute_name = The desired randomid attribute name, e.g. UID
|
43
|
+
* token_length = Is how long you want the token to be e.g. 5
|
44
|
+
|
45
|
+
E.g:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
rails generate randomid customer uid 5
|
49
|
+
```
|
50
|
+
|
51
|
+
This will also add the method to the model file:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class Customer < ActiveRecord::Base
|
55
|
+
unique_identifier :uid, 5
|
56
|
+
```
|
57
|
+
**Long**
|
58
|
+
|
31
59
|
Firstly, you need to make sure that each model you want to have a unique identifier for, you add an attribute to that model.
|
32
60
|
|
33
61
|
E.g.
|
34
62
|
If I wanted the User model to have a unique identifier I would add a "uid" attribute of type string.
|
35
63
|
|
64
|
+
|
36
65
|
*Note: You can name this attribute whatever you like*
|
37
66
|
|
38
67
|
Next navigate to that class's model file and add the following line:
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RandomidGenerator < Rails::Generators::Base
|
2
|
+
argument :model, type: :string
|
3
|
+
argument :attribute, type: :string
|
4
|
+
argument :length, type: :string
|
5
|
+
|
6
|
+
def add_attribute
|
7
|
+
generate 'migration', "add_#{attribute}_to_#{model} #{attribute}:string"
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_unique_identifier
|
11
|
+
inject_into_file "app/models/#{model}.rb", " unique_identifier :#{attribute}, #{length.to_i}\n", after: "class #{model.capitalize} < ActiveRecord::Base\n"
|
12
|
+
end
|
13
|
+
end
|
data/lib/randomid/version.rb
CHANGED
data/randomid-0.1.1.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: randomid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Lucas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".README.md.swp"
|
76
77
|
- ".gitignore"
|
77
78
|
- ".rspec"
|
78
79
|
- ".travis.yml"
|
@@ -83,11 +84,13 @@ files:
|
|
83
84
|
- Rakefile
|
84
85
|
- bin/console
|
85
86
|
- bin/setup
|
87
|
+
- lib/generators/randomid_generator.rb
|
86
88
|
- lib/randomid.rb
|
87
89
|
- lib/randomid/model_additions.rb
|
88
90
|
- lib/randomid/railtie.rb
|
89
91
|
- lib/randomid/version.rb
|
90
92
|
- randomid-0.1.0.gem
|
93
|
+
- randomid-0.1.1.gem
|
91
94
|
- randomid.gemspec
|
92
95
|
homepage: https://github.com/Harrisonl/randomid
|
93
96
|
licenses:
|