keytar 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +22 -31
- data/VERSION +1 -1
- data/keytar.gemspec +1 -1
- data/lib/keytar/key_builder.rb +3 -0
- data/spec/keytar/keytar_spec.rb +8 -8
- metadata +3 -3
data/README.md
CHANGED
@@ -57,48 +57,39 @@ Keys can be pre-defined and configured on a per key basis by calling **define\_k
|
|
57
57
|
|
58
58
|
class User
|
59
59
|
include Keytar
|
60
|
-
define_keys [:
|
60
|
+
define_keys [:friend_ids, :email_subscriptions, :news_feed], :delimiter => "|", :version => "v2"
|
61
61
|
define_keys :cassandra, :delimiter => "/", :version => 3, :key_prefix => "lol"
|
62
62
|
end
|
63
63
|
|
64
|
-
User.respond_to? :
|
65
|
-
User.
|
64
|
+
User.respond_to? :friend_ids_key #=> true
|
65
|
+
User.friend_ids_key #=> "user|friend_ids|v2"
|
66
66
|
|
67
67
|
Where the first argument is the key (or keys) to be defined, and the second argument is a hash of configurations. Using **define\_keys** is the recommended configuration method.
|
68
68
|
|
69
69
|
|
70
|
-
options can also be configured per class by passing in a hash to **key_config**:
|
70
|
+
global options can also be configured per class by passing in a hash to **key_config**:
|
71
71
|
|
72
72
|
class User
|
73
73
|
include Keytar
|
74
|
-
key_config :
|
74
|
+
key_config :delimiter => ":", :order => [:unique, :suffix], :prefix => "before"
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
class User
|
80
|
-
include Keytar
|
81
|
-
key_delimiter ":"
|
82
|
-
key_order [:prefix, :base, :name, :unique, :args, :suffix]
|
83
|
-
key_prefix nil
|
84
|
-
end
|
85
|
-
|
86
|
-
Config Options Breakdown
|
77
|
+
Configuration Options Breakdown
|
87
78
|
------------------------
|
88
79
|
Here is a run down of what each does
|
89
80
|
|
90
|
-
**
|
81
|
+
**delimiter** sets the separating argument in keys
|
91
82
|
|
92
|
-
|
83
|
+
:delimiter => "|"
|
93
84
|
user.redis_key #=> "users|redis"
|
94
85
|
|
95
86
|
|
96
|
-
**
|
87
|
+
**order** sets the location of key parts, if a symbol is omitted, it will not show up in the final key
|
97
88
|
|
98
|
-
|
89
|
+
:key_order =>[:name, :base]
|
99
90
|
user.redis_key #=> "redis:users"
|
100
91
|
|
101
|
-
**
|
92
|
+
**unique** sets the unique value of the instance that is used to build the key
|
102
93
|
|
103
94
|
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, but will not use id if object.id == object.object_id)
|
104
95
|
|
@@ -106,34 +97,34 @@ By default all instance keys have an identifying unique element included in the
|
|
106
97
|
user.id #=> 9
|
107
98
|
user.redis_key #=> "users:redis:9"
|
108
99
|
|
109
|
-
|
100
|
+
:unique => "username"
|
110
101
|
user.username #=> "schneems"
|
111
102
|
user.redis_key #=> "users:redis:schneems"
|
112
103
|
|
113
|
-
**
|
104
|
+
**prefix** adds some text to the beginning of your key for that class
|
114
105
|
|
115
|
-
|
106
|
+
:prefix => "woot"
|
116
107
|
User.redis_key #=> "woot:users:redis"
|
117
108
|
|
118
|
-
**
|
109
|
+
**suffix** adds some text to the end of your key for that class
|
119
110
|
|
120
|
-
|
111
|
+
:suffix => "slave"
|
121
112
|
User.redis_key #=> "users:redis:slave"
|
122
113
|
|
123
|
-
**`
|
114
|
+
**`pluralize_instances`** allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
|
124
115
|
|
125
|
-
|
116
|
+
:pluralize_instances => false
|
126
117
|
user.redis_key #=> "user:redis"
|
127
118
|
|
128
119
|
|
129
|
-
**
|
120
|
+
**plural** allows you to over-ride the default pluralize method with custom spelling
|
130
121
|
|
131
|
-
|
122
|
+
:plural => "uzerz"
|
132
123
|
user.redis_key #=> "uzerz:redis"
|
133
124
|
|
134
|
-
**
|
125
|
+
**case** allows you to specify the case of your key
|
135
126
|
|
136
|
-
|
127
|
+
:case => :upcase
|
137
128
|
User.redis_key #=> "USER:REDIS"
|
138
129
|
|
139
130
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/keytar.gemspec
CHANGED
data/lib/keytar/key_builder.rb
CHANGED
@@ -76,6 +76,9 @@ module KeyBuilder
|
|
76
76
|
|
77
77
|
# a way to define configurations for keytar using a hash
|
78
78
|
def key_config(options = {})
|
79
|
+
options.keys.each do |key|
|
80
|
+
options["key_#{key}".to_sym] = options[key] if key.to_s !~ /^key_/
|
81
|
+
end
|
79
82
|
options.keys.each do |key|
|
80
83
|
eval("@@#{key} = options[key]") if key.to_s =~ /^key_.*/
|
81
84
|
end
|
data/spec/keytar/keytar_spec.rb
CHANGED
@@ -187,14 +187,14 @@ describe Keytar do
|
|
187
187
|
key_plural = "zoosk"
|
188
188
|
key_unique = "doesn-t_apply_to_instance_methods"
|
189
189
|
# config
|
190
|
-
Foo.keyfig :
|
191
|
-
:
|
192
|
-
:
|
193
|
-
:
|
194
|
-
:
|
195
|
-
:
|
196
|
-
:
|
197
|
-
:
|
190
|
+
Foo.keyfig :delimiter => key_delimiter,
|
191
|
+
:order => key_order,
|
192
|
+
:prefix => key_prefix,
|
193
|
+
:suffix => key_suffix,
|
194
|
+
:pluralize_instances => key_pluralize_instances,
|
195
|
+
:case => key_case,
|
196
|
+
:plural => key_plural,
|
197
|
+
:unique => key_unique
|
198
198
|
# assertions
|
199
199
|
Foo.key_delimiter.should == key_delimiter
|
200
200
|
Foo.key_order.should == key_order
|
metadata
CHANGED