keytar 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -24
- data/VERSION +1 -1
- data/keytar.gemspec +2 -2
- data/lib/keytar/key_builder.rb +2 -4
- data/license.txt +2 -0
- data/spec/keytar/key_builder_spec.rb +1 -1
- data/spec/keytar/keytar_spec.rb +21 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -3,11 +3,23 @@ Keytar
|
|
3
3
|
|
4
4
|
**1.** A keyboard that is designed to be played standing up, like a guitar.
|
5
5
|
**2.** A crazy simple ruby-on-rails library for making re-usable keys (the kind you use in key/value stores)
|
6
|
+
It is an amazingly easy way generate keys for all of your NOSQL key needs. Are you using Redis, Memcache, MongoDB, Cassandra, or another hot key-value store? Then use **keytar**! It generates keys based on class name instead of cluttering model definitions with tons of redundant key method declarations.
|
6
7
|
|
7
|
-
It Builds Keys
|
8
|
-
----------
|
9
8
|
|
10
|
-
|
9
|
+
It Builds Keys:
|
10
|
+
--------
|
11
|
+
keytar auto-magically generates keys using method names ending in `"_key"` or simply "key"
|
12
|
+
|
13
|
+
User.key #=> "user"
|
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
|
+
|
11
23
|
|
12
24
|
___quit___ littering your code with junk like this:
|
13
25
|
|
@@ -17,7 +29,7 @@ ___quit___ littering your code with junk like this:
|
|
17
29
|
end
|
18
30
|
end
|
19
31
|
|
20
|
-
Seriously, ___quit it___!
|
32
|
+
Seriously, ___quit it___! Use Keytar instead ^_^
|
21
33
|
|
22
34
|
|
23
35
|
Installation
|
@@ -33,38 +45,23 @@ then run
|
|
33
45
|
Then drop `include Keytar` in any Ruby model you want and you're good to go
|
34
46
|
|
35
47
|
|
36
|
-
Example:
|
37
|
-
--------
|
38
|
-
keytar auto-magically generates keys using method names ending in `"_key"` or simply "key"
|
39
|
-
|
40
|
-
User.key #=> "user"
|
41
|
-
User.friends_key #=> "user:friends"
|
42
|
-
|
43
|
-
u = User.new
|
44
|
-
u.last_web_access_cache_key #=> "users:last_web_access_cache"
|
45
|
-
u.favorite_spots_key("some_argument") #=> "users:favorite_spots:some_argument"
|
46
|
-
|
47
|
-
u = User.create(:id => 2)
|
48
|
-
u.sweet_key #=> "users:sweet:2"
|
49
|
-
|
50
|
-
|
51
48
|
|
52
49
|
It's that simple
|
53
50
|
|
54
|
-
|
51
|
+
Define Keys
|
55
52
|
-------------
|
56
|
-
Keys
|
53
|
+
Keys should be pre-defined and configured by calling **define\_keys**:
|
57
54
|
|
58
55
|
class User
|
59
56
|
include Keytar
|
60
|
-
define_keys
|
57
|
+
define_keys :friend_ids, :email_subscriptions, :news_feed, :delimiter => "|", :version => "v2"
|
61
58
|
define_keys :favorite_spots, :delimiter => "/", :version => 3, :key_prefix => "lol"
|
62
59
|
end
|
63
60
|
|
64
61
|
User.respond_to? :friend_ids_key #=> true
|
65
62
|
User.friend_ids_key #=> "user|friend_ids|v2"
|
66
63
|
|
67
|
-
Where the first argument is the key (or keys) to be defined, and the second argument is a hash of configurations.
|
64
|
+
Where the first argument is the key (or keys) to be defined, and the second argument is a hash of configurations.
|
68
65
|
|
69
66
|
|
70
67
|
Global options can also be configured per class by passing in a hash to **key_config**:
|
@@ -90,7 +87,7 @@ Here is a run down of what each does
|
|
90
87
|
**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)
|
91
88
|
|
92
89
|
define_keys :favorite_spots, :order => [:name, :base]
|
93
|
-
User.favorite_spots_key #=> "favorite_spots:user
|
90
|
+
User.favorite_spots_key #=> "favorite_spots:user"
|
94
91
|
|
95
92
|
**unique** sets the unique value of the instance that is used to build the key
|
96
93
|
|
@@ -190,5 +187,6 @@ Contribution
|
|
190
187
|
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.
|
191
188
|
|
192
189
|
|
190
|
+
licensed under MIT License
|
193
191
|
Copyright (c) 2011 Schneems. See LICENSE.txt for
|
194
192
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/keytar.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{keytar}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Schneems"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-21}
|
13
13
|
s.description = %q{
|
14
14
|
Keytar is a Ruby on Rails wrapper for KeyBuilder.
|
15
15
|
Use KeyBuilder to automatically generate keys based on class name instead of cluttering model
|
data/lib/keytar/key_builder.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'key_utility') ## gives us support for Object#blank, Object#present?, String.pluralize without require ActiveSupport
|
2
2
|
|
3
3
|
module KeyBuilder
|
4
|
-
alias :original_method_missing :method_missing
|
5
|
-
|
6
4
|
DEFAULTS = {:key_delimiter => ":",
|
7
|
-
:key_order => [:prefix, :base, :name, :unique, :args, :suffix, :version, :v],
|
5
|
+
:key_order => [:shard, :prefix, :base, :name, :unique, :args, :suffix, :version, :v],
|
8
6
|
:key_prefix => nil,
|
9
7
|
:key_suffix => nil,
|
10
8
|
:key_pluralize_instances => true,
|
@@ -141,7 +139,7 @@ module KeyBuilder
|
|
141
139
|
if method_name.to_s =~ /.*key$/
|
142
140
|
build_key(:name => method_name, :args => args)
|
143
141
|
else
|
144
|
-
|
142
|
+
super
|
145
143
|
end
|
146
144
|
end
|
147
145
|
end
|
data/license.txt
CHANGED
@@ -75,7 +75,7 @@ describe KeyBuilder do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "converts a hash to an array based on default order" do
|
78
|
-
Foo.key_hash_to_ordered_array(@options).should == [@options[:prefix], @options[:base], @options[:name], @options[:unique], @options[:suffix], @options[:version], @options[:v]]
|
78
|
+
Foo.key_hash_to_ordered_array(@options).should == [@options[:shard], @options[:prefix], @options[:base], @options[:name], @options[:unique], @options[:suffix], @options[:version], @options[:v]]
|
79
79
|
end
|
80
80
|
|
81
81
|
it "order output using direct option before class config" do
|
data/spec/keytar/keytar_spec.rb
CHANGED
@@ -10,6 +10,9 @@ ActiveRecord::Schema.define do
|
|
10
10
|
create_table :bars do |t|
|
11
11
|
t.string :name, :null => false
|
12
12
|
end
|
13
|
+
create_table :bar_bazs do |t|
|
14
|
+
t.string :name, :null => false
|
15
|
+
end
|
13
16
|
end
|
14
17
|
|
15
18
|
class Foo
|
@@ -25,6 +28,10 @@ class BarNonActiveRecord
|
|
25
28
|
end
|
26
29
|
|
27
30
|
|
31
|
+
class BarBaz < ActiveRecord::Base
|
32
|
+
|
33
|
+
end
|
34
|
+
|
28
35
|
describe Keytar do
|
29
36
|
|
30
37
|
describe 'cache_key' do
|
@@ -242,5 +249,19 @@ describe Keytar do
|
|
242
249
|
end
|
243
250
|
end
|
244
251
|
|
252
|
+
describe "keytar should not over-ride default method_missing for AR" do
|
253
|
+
before do
|
254
|
+
b = BarBaz.create(:name => "something")
|
255
|
+
@id = b.id
|
256
|
+
Object.instance_eval{ remove_const :BarBaz } ## AR caches methods on object on create, need to pull it from disk
|
257
|
+
class BarBaz < ActiveRecord::Base
|
258
|
+
include Keytar
|
259
|
+
define_key :foo_key
|
260
|
+
end
|
261
|
+
end
|
245
262
|
|
263
|
+
it 'does not interfere with how ActiveRecord generates methods based on column names' do
|
264
|
+
BarBaz.last.id.should == @id
|
265
|
+
end
|
266
|
+
end
|
246
267
|
end
|
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:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
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-06-
|
18
|
+
date: 2011-06-21 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|