masked-identifier 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.markdown +107 -0
  2. metadata +21 -8
  3. data/README.txt +0 -53
data/README.markdown ADDED
@@ -0,0 +1,107 @@
1
+ # Masked Identifier
2
+
3
+ Masked Identifier makes it easy to add a non-incrementing identifier to any ActiveRecord object.
4
+
5
+ ## Installation
6
+
7
+ Add ```gem 'masked-identifier'``` to your Rails project Gemfile.
8
+
9
+ Verified to work with Rails 3.1.0.rc5. Let me know if you use it in older versions of Rails.
10
+
11
+ ## Usage
12
+
13
+ Add a column named 'masked_identifier' to the table of the ActiveRecord object that you want to
14
+ be able to refer to using a masked identifier. Also, don't forget to add an index for this new
15
+ column
16
+
17
+ ```ruby
18
+ def change
19
+ add_column :users, :masked_identifier
20
+ add_index :users, :masked_identifier
21
+ end
22
+ ```
23
+
24
+ Add ```has_masked_identifier``` to the ActiveRecord object
25
+
26
+ ```ruby
27
+ class User < ActiveRecord::Base
28
+ has_masked_identifier
29
+ end
30
+ ```
31
+
32
+ Create a new object and you'll see that a masked identifier has been added
33
+
34
+ ```ruby
35
+ user = User.create!(name: 'Matt')
36
+ user.masked_identifier
37
+ => "2xfYgm1pQ8"
38
+ ```
39
+
40
+ Lookup users based on the object's ```masked_identifier``` property
41
+
42
+ ```ruby
43
+ user = User.find_by_masked_identifier("2xfYgm1pQ8")
44
+ user.name
45
+ => "Matt"
46
+ ```
47
+
48
+ If you want ```User``` to automatically return ```masked_identifier``` instead of ```id``` when
49
+ ```to_param``` is called, you can override ```to_param``` in the ```User``` class
50
+
51
+ ```ruby
52
+ class User < ActiveRecord::Base
53
+ def to_param
54
+ self.masked_identifier
55
+ end
56
+ end
57
+ ```
58
+
59
+ ## Options
60
+
61
+ Masked Identifier lets you edit a number of settings by including an options hash following
62
+ ```has_masked_identifier```:
63
+
64
+ ```ruby
65
+ class User < ActiveRecord::Base
66
+ has_masked_identifier length: 8, property: 'mid', charset: %w{ a b c d }, attempts: 10
67
+ end
68
+ ```
69
+
70
+ _Note: This is for example purposes only. You should never use a charset this small. You run the
71
+ risk of running out of possible unique values and throwing a CodeGenerator::TooManyFailedAttempts
72
+ error._
73
+
74
+ * ```length``` - the number of characters to include in the masked identifier. _Note: As the
75
+ length is increased, the number of possible unique masked identifiers also increases_
76
+
77
+ * ```property``` - override the default ```masked_identifier``` property with a custom named
78
+ property. _Don't forget you'll need to use this custom name in your database migration too_
79
+
80
+ * ```charset``` - override the defailt character set used when generating masked identifiers
81
+ (default character set includes a-z, A-Z, and 0-9). _Note: As the size of the character set is
82
+ increased, the number of possible unique masked identifiers also increases_
83
+
84
+ * ```attempts``` - override the number of attempts to identifiy a unique masked identifier. Each
85
+ 'attempt' requires one SELECT query on the database. If you have a sufficiently large charset
86
+ and length >=10 chars, your app should rarely require more than one attempt
87
+
88
+ ## Exceptions
89
+
90
+ Make sure you handle the following possible exceptions in your applicaiton:
91
+
92
+ * ```[YourActiveRecordObject]::InvalidProperty``` - if object does not have a
93
+ ```masked_identifier``` property (or the custom property passed to the ```property``` option
94
+ does not exist)
95
+
96
+ * ```CodeGenerator::TooManyFailedAttempts``` - if unable to find a unique code to user as a masked
97
+ identifier
98
+
99
+ * ```CodeGenerator::InvalidAttemptsValue``` - if the value provided to the ```attempts``` option
100
+ is not an Integer or < 1
101
+
102
+ * ```CodeGenerator::InvalidCodeLength``` - if the value provided to the ```length``` option is not
103
+ an ```Integer``` or is < 1
104
+
105
+ * ```CodeGenerator::InvalidCharset``` - if value provided to the ```charset``` is not an
106
+ ```Array``` with a size >= 1
107
+
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: masked-identifier
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.2
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
12
  authors:
8
13
  - Matt Hodan
@@ -10,10 +15,11 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-08-01 00:00:00 Z
18
+ date: 2011-07-31 00:00:00 -07:00
19
+ default_executable:
14
20
  dependencies: []
15
21
 
16
- description: Automatically adds a masked identifier to an ActiveRecord object on create. Default assumes the ActiveRecord object contains a property called 'masked_identifier', which should be added to your database migration. Don't forget to add an index on this column!
22
+ description: Automatically adds a masked identifier to an ActiveRecord object on create. View the project GitHub page for more info.
17
23
  email:
18
24
  - matthew.c.hodan@gmail.com
19
25
  executables: []
@@ -28,7 +34,7 @@ files:
28
34
  - lib/tasks/masked-identifier_tasks.rake
29
35
  - MIT-LICENSE
30
36
  - Rakefile
31
- - README.txt
37
+ - README.markdown
32
38
  - test/dummy/app/assets/javascripts/application.js
33
39
  - test/dummy/app/assets/stylesheets/application.css
34
40
  - test/dummy/app/controllers/application_controller.rb
@@ -67,7 +73,8 @@ files:
67
73
  - test/dummy/test/unit/user_test.rb
68
74
  - test/masked-identifier_test.rb
69
75
  - test/test_helper.rb
70
- homepage: http://blog.matthodan.com/
76
+ has_rdoc: true
77
+ homepage: http://github.com/matthodan/masked-identifier
71
78
  licenses: []
72
79
 
73
80
  post_install_message:
@@ -80,20 +87,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
87
  requirements:
81
88
  - - ">="
82
89
  - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
83
93
  version: "0"
84
94
  required_rubygems_version: !ruby/object:Gem::Requirement
85
95
  none: false
86
96
  requirements:
87
97
  - - ">="
88
98
  - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
89
102
  version: "0"
90
103
  requirements: []
91
104
 
92
105
  rubyforge_project:
93
- rubygems_version: 1.8.6
106
+ rubygems_version: 1.3.7
94
107
  signing_key:
95
108
  specification_version: 3
96
- summary: Use a masked identifier as a not-incrementing reference to an ActiveRecord object
109
+ summary: Use a masked identifier as a non-incrementing reference to an ActiveRecord object
97
110
  test_files:
98
111
  - test/dummy/app/assets/javascripts/application.js
99
112
  - test/dummy/app/assets/stylesheets/application.css
data/README.txt DELETED
@@ -1,53 +0,0 @@
1
- = MaskedIdentifier
2
- #
3
- # MASKED IDENTIFIER DOCUMENTATION
4
- # ===============================
5
- #
6
- # Automatically adds a masked identifier to an ActiveRecord object on create. Default assumes the
7
- # ActiveRecord object contains a property called 'masked_identifier', which should be added to your
8
- # database migration. Don't forget to add an index on this column!
9
- #
10
- # Usage:
11
- # class User < ActiveRecord::Base
12
- # has_masked_identifier
13
- # end
14
- #
15
- # Or, with optional settings:
16
- # class User < ActiveRecord::Base
17
- # has_masked_identifier property: 'mid', attempts: 10, length: 8, charset: %w{ a b c d e }
18
- # end
19
- #
20
- # Optional (options hash):
21
- # property: override default property name with a custom name (default is 'masked_identifier')
22
- # attempts: number of attempts to try to find a unique code (default is 20)
23
- # length: number of characters to include in masked identifier code (default is 10)
24
- # charset: character set to use when generating codes (default includes a-z, A-Z, and 0-9)
25
- #
26
- # Possible Errors:
27
- # [YourActiveRecordObject]::InvalidProperty if property does not exist
28
- # See CodeGenerator for additional errors
29
- #
30
- #
31
- # CODE GENERATOR DOCUMENTATION
32
- # ============================
33
- #
34
- # Generates a unique code based on a property of an ActiveRecord object
35
- #
36
- # Usage:
37
- # code = CodeGenerator.unique_code(klass, property, options = {})
38
- #
39
- # Required parameters:
40
- # klass = the ActiveRecord object
41
- # property = the name of the property to check for uniqueness
42
- #
43
- # Optional (options hash):
44
- # length: number of characters to include in code (default = 10)
45
- # charset: character set to use when generating codes (default = a-zA-Z0-9)
46
- # attempts: number of attempts to find a unique code (default = 20)
47
- #
48
- # Possible Errors:
49
- # CodeGenerator::TooManyFailedAttempts if unable to find a unique code
50
- # CodeGenerator::InvalidAttemptsValue if value provided is not an Integer or < 1
51
- # CodeGenerator::InvalidCodeLength if value provided is not an Integer or < 1
52
- # CodeGenerator::InvalidCharset if value provided is not an Array with size >= 1
53
- #