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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcdb88f215dad0b4771faa995758484257e174bf
4
- data.tar.gz: 9dba60272a8e6e1cb89ad17b6169be9bffd5e5ce
3
+ metadata.gz: 0f8b8d5cdc82b1575d85d0256d1804c108e9583a
4
+ data.tar.gz: ae014ad5fb7d4b76f6a90fb01008fa9d628de1cc
5
5
  SHA512:
6
- metadata.gz: 7c5796ad5eee1ca812d460a2e7d7cc986ce8e9b09a0698e76b1d203579ed361ff8f099abaeaae925c9996ea4330f6f8f81ae71e45c7bbbb5653aef01ea23cc7f
7
- data.tar.gz: 74766c04df7abfd0af38eb20ec9d318d65f1645dcb92d9c5d54b34281d50dd014c199ca3e11e90581d58f359aed5c59b09781670117b9da834c907136577e1f1
6
+ metadata.gz: 40fa662e5ab49ba8f60dca40230747d75c52147585680c4c06f80bec01d5b46d4733bade3bbba7f2ee915a9382d050aab7385ca32c3ca6c45a6017a1f9838d32
7
+ data.tar.gz: 0690165c4972e085fbe832946a4fc2b9ffc49cd4aede9045b3f0c68bef22b9d705a5d5857f9bda7474101112d79b6e5336abd25ca127e9b4cdcef6899110508b
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
@@ -1,4 +1,3 @@
1
-
2
1
  module Randomid
3
2
  module ModelAdditions
4
3
 
@@ -10,7 +9,5 @@ module Randomid
10
9
  end
11
10
  end
12
11
  end
13
-
14
-
15
12
  end
16
13
  end
@@ -1,3 +1,3 @@
1
1
  module Randomid
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-16 00:00:00.000000000 Z
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: