token_phrase 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,18 +23,18 @@ Or install it yourself as:
23
23
  ## TokenPhrase.generate(separator = nil, dictionaries = {})
24
24
 
25
25
  ### Defaults
26
- By default, TokenPhrase uses the included dictionaries and separates everything with a hyphen (-):
26
+ By default, TokenPhrase uses the included dictionaries, separates everything with a hyphen (-), and appends a random number between 1 and 1,000,000 :
27
27
 
28
28
  ```ruby
29
29
  TokenPhrase.generate
30
- => "ultimate-blue-glossy-lamp"
30
+ => "ultimate-beige-tartan-pants557846"
31
31
 
32
32
  5.times { p TokenPhrase.generate }
33
- "energetic-white-checked-book"
34
- "genetically-modified-red-argyle-lego-set"
35
- "strong-yellow-wavy-machine"
36
- "sugarfilled-blue-glossy-jacket"
37
- "sour-ultraviolet-plaid-sand"
33
+ "amazing-golden-plaid-dishwasher214832"
34
+ "thunderous-yellow-matte-greyhound516648"
35
+ "bodacious-violet-houndstooth-viper351290"
36
+ "dancing-golden-spotted-cardinal623081"
37
+ "sweet-jade-cracked-cape975328"
38
38
  ```
39
39
 
40
40
  ### Separators
@@ -42,10 +42,10 @@ If you would like a different separator, just pass a string as an argument:
42
42
 
43
43
  ```ruby
44
44
  TokenPhrase.generate('$')
45
- => "exciting$taupe$glossy$lake"
45
+ => "vegan$blue$spotted$capybara649484"
46
46
 
47
- TokenPhrase.generate('!!!eric!!!')
48
- => "splendid!!!eric!!!golden!!!eric!!!glossy!!!eric!!!flounder"
47
+ TokenPhrase.generate('MARSIPAN')
48
+ => "bodaciousMARSIPANaquaMARSIPANmatteMARSIPANcardinal611650"
49
49
  ```
50
50
 
51
51
  ### Dictionaries
@@ -60,35 +60,44 @@ If you want to replace the dictionary, just pass a hash with an array as an argu
60
60
 
61
61
  ```ruby
62
62
  TokenPhrase.generate :adjectives => %w(glowing)
63
- => "glowing-tan-striped-sand"
63
+ => "glowing-white-striped-tapir168706"
64
64
 
65
65
  5.times { p TokenPhrase.generate :nouns => %w(Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto) }
66
- "home-made-lime-plaid-Pluto"
67
- "bluetooth-lime-wavy-Jupiter"
68
- "sugarfilled-tan-pinstriped-Mars"
69
- "magnetic-pink-polka-dotted-Saturn"
70
- "grandmas-white-plaid-Pluto"
66
+ "better-red-satin-Venus956045"
67
+ "awesome-pearl-glossy-Saturn284244"
68
+ "sour-sea-green-checked-Saturn711076"
69
+ "groovy-lime-argyle-Venus213795"
70
+ "old-fashioned-topaz-waved-Pluto922970"
71
71
  ```
72
72
  You can pass multiple dictionaries:
73
73
 
74
74
  ```ruby
75
75
  5.times { p TokenPhrase.generate :colors => %w(black white), :nouns => %w(cat dog) }
76
- "spectacular-white-argyle-dog"
77
- "wind-up-white-plaid-cat"
78
- "glazed-white-polka-dotted-cat"
79
- "bodacious-white-checked-cat"
80
- "genetically-modified-white-pinstriped-dog"
76
+ "grass-fed-white-polka-dotted-cat307486"
77
+ "grass-fed-black-cracked-cat882907"
78
+ "bluetooth-white-satin-dog77769"
79
+ "ultimate-black-fractal-dog328541"
80
+ "spectacular-black-satin-cat815018"
81
81
  ```
82
82
 
83
83
  And you can, of course pass a separator before the dictionaries:
84
84
 
85
85
  ```ruby
86
86
  5.times { p TokenPhrase.generate '^^^', :patterns => %w(striped), :adjectives =>%w(great awesome) }
87
- "great^^^brown^^^striped^^^door"
88
- "great^^^silver^^^striped^^^carpenter"
89
- "great^^^lime^^^striped^^^crane"
90
- "great^^^taupe^^^striped^^^envelope"
91
- "great^^^pink^^^striped^^^sand"
87
+ "great^^^cornflower^^^blue^^^striped^^^machine662941"
88
+ "awesome^^^pearl^^^striped^^^banana^^^slug313429"
89
+ "awesome^^^navy^^^blue^^^striped^^^shirt279849"
90
+ "awesome^^^midnight^^^blue^^^striped^^^shark379464"
91
+ "awesome^^^ultraviolet^^^striped^^^hat748152"
92
+ ```
93
+
94
+ ## Numbers
95
+
96
+ To help with uniqueness, a random number is added to the token by default. This may not be your cup of tea, so if you pass :numbers => false with the dictionaries, you can remove the number:
97
+
98
+ ```ruby
99
+ TokenPhrase.generate(:numbers => false)
100
+ => "glazed-magenta-houndstooth-spider-wolf"
92
101
  ```
93
102
 
94
103
  ## Dictionary Methods
@@ -108,6 +117,23 @@ TokenPhrase.generate :patterns => your_patterns
108
117
  => "awesome-mauve-magic-eye-giraffe"
109
118
  ```
110
119
 
120
+ ## Uniqueness
121
+
122
+ The simplest way to create a unique token for your models is to add a before_create filter to your model:
123
+
124
+ ```ruby
125
+ #assuming your Thing model has a token property
126
+ class Thing < ActiveRecord::Base
127
+ before_create :generate_token
128
+
129
+ private
130
+ def generate_token
131
+ begin
132
+ self.token = TokenPhrase.generate
133
+ end while self.class.exists?(token: token)
134
+ end
135
+ end
136
+ ```
111
137
 
112
138
  ## Contributing
113
139
 
@@ -116,3 +142,7 @@ TokenPhrase.generate :patterns => your_patterns
116
142
  3. Commit your changes (`git commit -am 'Add some feature'`)
117
143
  4. Push to the branch (`git push origin my-new-feature`)
118
144
  5. Create new Pull Request
145
+
146
+ ## Sellmer
147
+
148
+ I built TokenPhrase for use with [Sellmer](http://justsellstuff.com). I'm using token phrases for public-facing sales tokens as a way to give the application a little more personality and to make supporting sales and transactions easier. Sellmer is almost ready for beta testers, so if you are interested in being one of the first people to get their hands on it, head over to the [Sellmer page](http://justsellstuff.com) and add your email to the list. I'm looking forward to launching with features as big and as small as token phrase.
@@ -1,3 +1,3 @@
1
1
  module TokenPhrase
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
data/lib/token_phrase.rb CHANGED
@@ -2,8 +2,8 @@ require "token_phrase/version"
2
2
 
3
3
  module TokenPhrase
4
4
  Adjectives = %w(splendid superior spectacular amazing ultimate ferocious exciting lovely old-fashioned home-made grass-fed free-range grandmas grandpas governing prickly strong stellar awesome wonderful bodacious excellent stupendous groovy dancing energetic sweet sour sugarfilled glazed vegan letterman thunderous established magnetic better windy wind-up american soft genetically-modified tailored liberal conservative bluetooth)
5
- Colors = %w(red yellow blue green violet taupe mauve lime golden silver grey black white tangello sunshine brown tan infrared ultraviolet pink beige)
6
- Patterns = %w(striped checked spotted polka-dotted plaid wavy houndstooth argyle glossy matte pinstriped)
5
+ Colors = %w(red yellow blue green violet taupe mauve lime golden silver grey black white tangello sunshine brown tan infrared ultraviolet pink beige almond aquamarine burnt-orange cerulean cornflower-blue denim forest-green midnight-blue peach plum sea-green ruby emerald jade rose topaz onyx pearl coral crimson cyan chocolate aqua azure lavendar chiffon khaki ivory magenta navy-blue olive salmon turquoise)
6
+ Patterns = %w(striped checked spotted polka-dotted plaid wavy houndstooth argyle glossy matte pinstriped tartan paisley satin honeycomb fractal waved cracked )
7
7
  Nouns = %w(floutist carpenter jacket president address machine computer mug lamp phone wall bicycle river lake fountain building book hat pants shirt cape soup gloves pen suit photograph sand profit energy fork compact-disk floppy-disk chandelier door window laboratory people tapir wolverine wolf spider wolf-spider spider-wolf banana-slug giraffe deer-mouse capybara dingo dragon cardinal owl octopus elk moose weasel elephant rhino iguana bullfrog greyhound stickbug ladybug ant rat coyote chimpanzee housecat barracuda raven crane fox panda racoon nessie whale dolphin shark viper frog toad flounder skunk wookie dishwasher bat space-heater bobble-head lego-set pinboard flag tv video-game envelope headphones mousepad jukebox)
8
8
 
9
9
  def self.adjectives(more_adjectives = nil)
@@ -32,6 +32,7 @@ module TokenPhrase
32
32
  dictionaries[:patterns] ||= TokenPhrase::Patterns
33
33
  dictionaries[:nouns] ||= TokenPhrase::Nouns
34
34
  phrase = [dictionaries[:adjectives].sample, dictionaries[:colors].sample, dictionaries[:patterns].sample, dictionaries[:nouns].sample].join('-')
35
+ phrase << [*1..1000000].sample.to_s unless dictionaries[:numbers] == false
35
36
  phrase.gsub!(/-/, separator) unless separator.nil?
36
37
  return phrase
37
38
  end
data/token_phrase.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["eric@notvelcro.com"]
11
11
  gem.description = %q{A token-phrase generator}
12
12
  gem.summary = %q{Token Phrase is a simple generator that creates friendlier unique tokens as phrases}
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/genericsteele/token_phrase"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: token_phrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -26,7 +26,7 @@ files:
26
26
  - lib/token_phrase.rb
27
27
  - lib/token_phrase/version.rb
28
28
  - token_phrase.gemspec
29
- homepage: ''
29
+ homepage: https://github.com/genericsteele/token_phrase
30
30
  licenses: []
31
31
  post_install_message:
32
32
  rdoc_options: []