File: README.md

package info (click to toggle)
ruby-model-tokenizer 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 156 kB
  • sloc: ruby: 248; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 2,291 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# ModelTokenizer

Generates random tokens that models can be accessed by. Instead of

```
somesite.com/video/71589
```

you'll get

```
somesite.com/video/j5-drkENpSDBNRds
```

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'model_tokenizer'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install model_tokenizer

## Usage

1. Run

        $ rails g model_tokenizer MODEL_NAME [field:type field:type ... ]

  to create a new tokenized model. If the model already exists, ModelTokenizer will integrate into it by injecting the following code

  ```ruby
    extend ModelTokenizer
    has_token
  ```

  The appropriate migration will also be created, which will create the ```token``` field and its associated unique index.

  The default token length is 14, but you can change it (no lower than 8)

  ```ruby
    has_token :length => 16
  ```

2. In the model file, make sure the following line is there:

  ```ruby
  self.primary_key = :token
  ```

  The generator will automatically inject this, but if you're doing something weird that involves manually installing ModelTokenizer without using the generators, make sure the aforementioned line exists.


## Notes

ModelTokenizer generates tokens from the following charset:

```
a b c d e f g h i j k   m n o p q r s t u v w x y z
A B C D E F G H   J K L M N   P   R S T     W X Y Z
2 3 4 5 6 7 8 9
- _
```

As you may have noticed, the following ambiguous characters have been removed

* Lowercase: l
* Uppercase: I, O, Q, U, V
* Numerals:  1, 0

However, the gem doesn't check for awkward tokens that could be confusing, has too many repeating characters, too many underscores/hyphens or otherwise makes someone raise an eyebrow (e.g. DXMHMHLALAH, _-aj-a2j6f-qacins-). Additionally, ModelTokenizer doesn't detect whether or not it has run out of combinations for 
generating new tokens, though this will be dealt with in the future.

ModelTokenizer has been tested with Rails 3 and 4.

## Contributing

1. Fork it ( https://github.com/adibsaad/model_tokenizer/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request