keytar 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,33 +1,44 @@
1
1
  Keytar
2
2
  ======
3
3
 
4
- **1.** A keyboard that is designed to be played standing up, like a guitar.
5
- **2.** A crazy simple, flexible ruby library for generating NOSQL keys. Use it with redis, memcache, mongo, or any other key-value store.
4
+ **1.** A keyboard that is designed to be played standing up, like a guitar.
5
+
6
+ **2.** A crazy simple, flexible ruby library for generating NOSQL keys. Use it with redis, memcache, mongo, or any other key-value store.
6
7
 
7
8
  It Builds Keys
8
9
  --------
9
- class User
10
- include Keytar
11
- define_keys :friends, :last_web_access_cache, :favorite_spots, :sweet
12
- end
13
-
14
- User.friends_key #=> "user:friends"
15
-
16
- u = User.new
17
- u.last_web_access_cache_key #=> "users:last_web_access_cache"
18
- u.favorite_spots_key("some_argument") #=> "users:favorite_spots:some_argument"
19
-
20
- u = User.create(:id => 2)
21
- u.sweet_key #=> "users:sweet:2"
22
-
10
+
11
+ ```ruby
12
+ class User
13
+ include Keytar
14
+ define_keys :friends, :favorite_spots, :sweet
15
+ end
16
+
17
+ user = User.find(22)
18
+ user.friends_key #=> "users:friends:22"
19
+ User.friends_key #=> "user:friends"
20
+
21
+ user = User.find(12)
22
+ user.favorite_spots_key #=> "users:favorite_spots:12"
23
+ user.favorite_spots_key("some_argument") #=> "users:favorite_spots:12:some_argument"
24
+ User.favorite_spots_key #=> "user:favorite_spots"
25
+
26
+
27
+ user = User.find(9)
28
+ user.sweet_key #=> "users:sweet:9"
29
+ user.sweet_key("foo") #=> "users:sweet:9:foo"
30
+ User.sweet_Key #=> "user:sweet"
31
+ ```
23
32
 
24
33
  ___quit___ littering your code with junk like this:
25
34
 
26
- class User
27
- def some_key_for_a_distributed_no_sql_datastore_key
28
- "foos:some_key_for_a_distributed_no_sql_datastore_key:#{self.id}"
29
- end
35
+ ```ruby
36
+ class User
37
+ def some_key_for_a_distributed_no_sql_datastore_key
38
+ "foos:some_key_for_a_distributed_no_sql_datastore_key:#{self.id}"
30
39
  end
40
+ end
41
+ ```
31
42
 
32
43
  Use Keytar instead ^_^
33
44
 
@@ -51,139 +62,160 @@ Define Keys
51
62
  -------------
52
63
  Keys should be pre-defined and configured by calling **define\_keys**:
53
64
 
54
- class User
55
- include Keytar
56
- define_keys :friend_ids, :email_subscriptions, :news_feed, :delimiter => "|", :version => "v2"
57
- end
58
-
59
- User.respond_to? :friend_ids_key #=> true
60
- User.friend_ids_key #=> "user|friend_ids|v2"
65
+ ```ruby
66
+ class User
67
+ include Keytar
68
+ define_keys :friend_ids, :email_subscriptions, :news_feed, :delimiter => "|"
69
+ end
61
70
 
71
+ User.friend_ids_key #=> "user|friend_ids"
72
+ User.find(9).friend_ids_key #=> "users|friend_ids|9"
73
+ ```
62
74
 
63
75
  Where the first argument is the key (or keys) to be defined, and the second argument is a hash of configuration options.
64
76
 
65
77
 
66
78
  Global options can also be configured per class by passing in a hash to **key_config**:
67
79
 
68
- class User
69
- include Keytar
70
- key_config :delimiter => "/", :suffix => "after"
71
- define_keys :ignored_ids
72
- end
80
+ ```ruby
81
+ class User
82
+ include Keytar
83
+ key_config :delimiter => "/", :suffix => "after"
84
+ define_keys :ignored_ids
85
+ end
86
+
87
+ User.ignored_ids_key #=> "user/ignored_ids/after"
88
+ User.find(9).ignored_ids_key #=> "user/ignored_ids/9/after"
89
+ ```
90
+
73
91
 
74
- User.ignored_ids_key #=> "user/ignored_ids/after"
92
+ But Wait there's more
93
+ ---------------------
94
+ Keytar is used to generate keys in my Rails method cache library [JohnnyCache](http://github.com/schneems/johnny_cache). Check it out as an easy way to speed up your rails app and make use of Rails.cache.
75
95
 
76
96
  Configuration Options Breakdown
77
97
  ------------------------
78
- Here is a run down of what each does
98
+ Here is a run down of what each does
79
99
 
80
100
  **delimiter** sets the separating argument in keys
81
101
 
102
+ ```ruby
82
103
  define_keys :favorite_spots, :delimiter => "|"
83
104
  User.favorite_spots_key #=> "user|favorite_spots"
84
-
105
+ ```
85
106
 
86
107
  **order** sets the location of key parts, if a symbol is omitted, it will not show up in the final key (note the location of "favorite_spots" and "user" is flipped)
87
108
 
109
+ ```ruby
88
110
  define_keys :favorite_spots, :order => [:name, :base]
89
111
  User.favorite_spots_key #=> "favorite_spots:user"
90
-
112
+ ```
91
113
  **unique** sets the unique value of the instance that is used to build the key
92
114
 
93
115
  By default all instance keys have an identifying unique element included in the key, specifying `key_unique` allows you to change the field that is used to specify a unique key. (defaults to database backed id, Object#id)
94
116
 
117
+ ```ruby
95
118
  User.create(:username => "Schneems", :id => 9)
96
119
  User.find(9).favorite_spots_key #=> "users:favorite_spots:9"
97
120
 
98
121
  define_keys :favorite_spots, :unique => "username"
99
122
  User.find(9).favorite_spots_key #=> "users:favorite_spots:schneems"
123
+ ```
100
124
 
101
125
  **prefix** adds some text to the beginning of your key for that class
102
126
 
127
+ ```ruby
103
128
  define_keys :favorite_spots, :prefix => "woot"
104
129
  User.favorite_spots_key #=> "woot:user:favorite_spots"
105
-
130
+ ```
131
+
106
132
  **suffix** adds some text to the end of your key for that class
107
133
 
134
+ ```ruby
108
135
  define_keys :favorite_spots, :suffix => "pow"
109
136
  User.favorite_spots_key #=> "user:favorite_spots:pow"
137
+ ```
110
138
 
111
- **`pluralize_instances`** allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
139
+ **pluralize_instances** allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
112
140
 
141
+ ```ruby
113
142
  define_keys :favorite_spots, :pluralize_instances => false
114
143
  User.find(1).favorite_spots_key #=> "user:favorite_spots:1"
115
-
144
+ ```
116
145
 
117
146
  **plural** allows you to over-ride the default pluralize method with custom spelling
118
147
 
148
+ ```ruby
119
149
  define_keys :favorite_spots, :plural => "uzerz"
120
150
  User.find(1).favorite_spots_key #=> "uzerz:favorite_spots:1"
151
+ ```
121
152
 
122
153
  **case** allows you to specify the case of your key
123
154
 
155
+ ```ruby
124
156
  define_keys :favorite_spots, :case => :upcase
125
157
  User.favorite_spots_key #=> "USER:REDIS"
126
-
158
+ ```
127
159
 
128
160
  Since this library is sooooo simple, here is a ASCII keytar for you. Thanks for checking it out.
129
161
 
130
- ,,,,
131
- ,,:::,
132
- ,,,,7::=
133
- ,:~?MOZN~
134
- ,,=~ONZDM
135
- ,,,~,NMOM+
136
- :,,:~MNOM,
137
- ,,,:,,MO8M
138
- :,,,,:: NO
139
- ,:,~=~+,,:~
140
- ,:::+:I:=::,
141
- =?::::I::::
142
- ,~:,+7:::::~
143
- ~,,,,,,+~::: ,,,
144
- ,:,,,,,=,,,7~: ,::::,
145
- ,:,,:,,?~::=:,+=:,,,,,,,::::::
146
- ::::,,:,,NMZ,=,,+=::,::::+::::
147
- ~:,,,::,88=DNM:,:,:+~:::,MN~,~
148
- ,:,,:,,,+=+MM==8MZ,=::::::?=:~~
149
- ~,,: ,,=,7MN~OMM=?NM::~:$+:~:=
150
- ~:,:,:,~7~:==MM?+ZM8~7::I~:+:::
151
- ,:,,,,,~,:NM8:=~$MD?+M~::~~~~~~
152
- ~,:,, +,+DO=?MM~,=~NM8:::I+:::~
153
- ,~:,:,=:,:~+MM8=ZMD:~::::+:~::~
154
- ~:,:,:,,?DZ:?~ONM=+MM:+~:I?~:~
155
- ~~,,,~:,ZN=?MN~::~OMO~:NMM:,::~
156
- ,~:,:~,,==+ZM8+8MZ:::~=+8D+,===,
157
- ~:,~=,,=,$MD++MM~?MMO::ND8,===~
158
- ,:,:,,:=:~:==MMD=OMO~Z=~=+?:===:
159
- ~,:,,,=,:ZM8~=:=NN?+M+::I7+~==:
160
- ~:::,,=,+DN=?MM~,=~ZM8:~7~::~~=
161
- ,~::,:=,:~~~8MZ+OM8~,~::==::=~:,
162
- ~:,: =,,?D$~~~+MN=+NMO::$~~~~~=
163
- ~,,~,:,=+=DMZ~~~+NN==$,::?~~::=
164
- ,,:~,::=,~NN+IMM$:+=8D,:::~~+~=
165
- ~,::,::,=D8?OMZ??NN:~:::?I:~:~
166
- :,:,:,:,,+~=MN+?MDZ+DM::+7::~~=
167
- ,::,,,~,:NN~~?~OM8+8MN:::N:~~:=,
168
- :~,,:~,,$$+8MM~~~=MN==::=Z~~:~~
169
- ,:,::,,,~,+MN+I8M$~+~Z,:==~~~~~
170
- :,,,,,,=I\~+~DM$=?MN::::::~+~+
171
- ~,::,,,=~=?M\~=~?MN7=O:::$~=:~,
172
- :,~,,,=,~NN$+N\ :~:+MI::N:::~=
173
- ,:=:,,+,=DZ?DMN+7M\:==,:~::=~=
174
- ::::~::,::+MN+?DN7+N\,:~::=:=
175
- ::::::,~::,?:DMN+?MN~~ :::~::
176
- :::::::,I:,~:+8NZ=,:=+I::~
177
- ,,:::::+:,,+:=$::$7::~
178
- :,:::,I:,,,:?7=:~~
179
- I:,:::::::$7I,:~
180
- ,::::~:,7:::
162
+ ,,,,
163
+ ,,:::,
164
+ ,,,,7::=
165
+ ,:~?MOZN~
166
+ ,,=~ONZDM
167
+ ,,,~,NMOM+
168
+ :,,:~MNOM,
169
+ ,,,:,,MO8M
170
+ :,,,,:: NO
171
+ ,:,~=~+,,:~
172
+ ,:::+:I:=::,
173
+ =?::::I::::
174
+ ,~:,+7:::::~
175
+ ~,,,,,,+~::: ,,,
176
+ ,:,,,,,=,,,7~: ,::::,
177
+ ,:,,:,,?~::=:,+=:,,,,,,,::::::
178
+ ::::,,:,,NMZ,=,,+=::,::::+::::
179
+ ~:,,,::,88=DNM:,:,:+~:::,MN~,~
180
+ ,:,,:,,,+=+MM==8MZ,=::::::?=:~~
181
+ ~,,: ,,=,7MN~OMM=?NM::~:$+:~:=
182
+ ~:,:,:,~7~:==MM?+ZM8~7::I~:+:::
183
+ ,:,,,,,~,:NM8:=~$MD?+M~::~~~~~~
184
+ ~,:,, +,+DO=?MM~,=~NM8:::I+:::~
185
+ ,~:,:,=:,:~+MM8=ZMD:~::::+:~::~
186
+ ~:,:,:,,?DZ:?~ONM=+MM:+~:I?~:~
187
+ ~~,,,~:,ZN=?MN~::~OMO~:NMM:,::~
188
+ ,~:,:~,,==+ZM8+8MZ:::~=+8D+,===,
189
+ ~:,~=,,=,$MD++MM~?MMO::ND8,===~
190
+ ,:,:,,:=:~:==MMD=OMO~Z=~=+?:===:
191
+ ~,:,,,=,:ZM8~=:=NN?+M+::I7+~==:
192
+ ~:::,,=,+DN=?MM~,=~ZM8:~7~::~~=
193
+ ,~::,:=,:~~~8MZ+OM8~,~::==::=~:,
194
+ ~:,: =,,?D$~~~+MN=+NMO::$~~~~~=
195
+ ~,,~,:,=+=DMZ~~~+NN==$,::?~~::=
196
+ ,,:~,::=,~NN+IMM$:+=8D,:::~~+~=
197
+ ~,::,::,=D8?OMZ??NN:~:::?I:~:~
198
+ :,:,:,:,,+~=MN+?MDZ+DM::+7::~~=
199
+ ,::,,,~,:NN~~?~OM8+8MN:::N:~~:=,
200
+ :~,,:~,,$$+8MM~~~=MN==::=Z~~:~~
201
+ ,:,::,,,~,+MN+I8M$~+~Z,:==~~~~~
202
+ :,,,,,,=I\~+~DM$=?MN::::::~+~+
203
+ ~,::,,,=~=?M\~=~?MN7=O:::$~=:~,
204
+ :,~,,,=,~NN$+N\ :~:+MI::N:::~=
205
+ ,:=:,,+,=DZ?DMN+7M\:==,:~::=~=
206
+ ::::~::,::+MN+?DN7+N\,:~::=:=
207
+ ::::::,~::,?:DMN+?MN~~ :::~::
208
+ :::::::,I:,~:+8NZ=,:=+I::~
209
+ ,,:::::+:,,+:=$::$7::~
210
+ :,:::,I:,,,:?7=:~~
211
+ I:,:::::::$7I,:~
212
+ ,::::~:,7:::
181
213
 
182
214
 
183
215
  Contribution
184
216
  ============
185
217
 
186
- Fork away. If you want to chat about a feature idea, or a question you can find me on the twitters [@schneems](http://twitter.com/schneems). Put any major changes into feature branches. Make sure all tests stay green, and make sure your changes are covered.
218
+ Fork away. If you want to chat about a feature idea, or a question you can find me on the twitters [@schneems](http://twitter.com/schneems). Put any major changes into feature branches. Make sure all tests stay green, and make sure your changes are covered.
187
219
 
188
220
 
189
221
  licensed under MIT License
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.1
1
+ 1.5.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{keytar}
8
- s.version = "1.5.1"
8
+ s.version = "1.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Schneems}]
12
- s.date = %q{2011-08-12}
12
+ s.date = %q{2011-08-21}
13
13
  s.description = %q{
14
14
  Use Keytar to automatically generate keys based on class name instead of cluttering model
15
15
  definitions with tons of redundant key method declarations.
@@ -28,7 +28,7 @@ module Keytar
28
28
 
29
29
  def to_s
30
30
  key = key_array.join(delimiter)
31
- key = key.send key_case if key_case.present?
31
+ key = key.send key_case if key_case.present? && key.respond_to?(key_case)
32
32
  key
33
33
  end
34
34
 
@@ -33,6 +33,7 @@ class BarBaz < ActiveRecord::Base
33
33
  end
34
34
 
35
35
  describe Keytar do
36
+
36
37
  describe 'class and instance interference' do
37
38
  it 'should not happen' do
38
39
  bar = Bar.create(:name => "whatever")
@@ -45,6 +46,20 @@ describe Keytar do
45
46
 
46
47
  describe 'define_key' do
47
48
 
49
+ it 'lets us not change key case when :key_case => :none is passed' do
50
+ Foo.define_key(:cached_instance_method, :key_case => nil)
51
+ @foo = Foo.new
52
+ key = @foo.cached_instance_method_key("NotUpCaseOrDownCase")
53
+ key.should eq("Foos:cached_instance_method:NotUpCaseOrDownCase")
54
+ end
55
+
56
+ it 'lets us not change key case when :key_case => nil is passed' do
57
+ Foo.define_key(:cached_instance_method, :key_case => nil)
58
+ @foo = Foo.new
59
+ key = @foo.cached_instance_method_key("NotUpCaseOrDownCase")
60
+ key.should eq("Foos:cached_instance_method:NotUpCaseOrDownCase")
61
+ end
62
+
48
63
  it 'allows us to pre-define instance methods' do
49
64
  Foo.define_key(:cached_instance_method, :delimiter => "|", :version => "3")
50
65
  @foo = Foo.new
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keytar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 1
10
- version: 1.5.1
9
+ - 2
10
+ version: 1.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Schneems
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-12 00:00:00 Z
18
+ date: 2011-08-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement