keytar 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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 [:zoolander, :something_about_mary, :tropic_thunder], :delimiter => "|", :version => 2
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? :zoolander_key #=> true
65
- User.zoolander_key #=> "user|zoolander|2"
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 :key_delimiter => ":", :key_order => [:unique, :suffix], :key_prefix => "before"
74
+ key_config :delimiter => ":", :order => [:unique, :suffix], :prefix => "before"
75
75
  end
76
76
 
77
- Or by calling class methods
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
- **key_delimiter** sets the separating argument in keys
81
+ **delimiter** sets the separating argument in keys
91
82
 
92
- User.key_delimiter "|"
83
+ :delimiter => "|"
93
84
  user.redis_key #=> "users|redis"
94
85
 
95
86
 
96
- **key_order** sets the location of key parts, if a symbol is omitted, it will not show up in the final key
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
- User.key_order [:name, :base]
89
+ :key_order =>[:name, :base]
99
90
  user.redis_key #=> "redis:users"
100
91
 
101
- **key_unique** sets the unique value of the instance that is used to build the key
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
- User.key_unique("username")
100
+ :unique => "username"
110
101
  user.username #=> "schneems"
111
102
  user.redis_key #=> "users:redis:schneems"
112
103
 
113
- **key_prefix** adds some text to the beginning of your key for that class
104
+ **prefix** adds some text to the beginning of your key for that class
114
105
 
115
- User.key_prefix "woot"
106
+ :prefix => "woot"
116
107
  User.redis_key #=> "woot:users:redis"
117
108
 
118
- **key_suffix** adds some text to the end of your key for that class
109
+ **suffix** adds some text to the end of your key for that class
119
110
 
120
- User.key_suffix "slave"
111
+ :suffix => "slave"
121
112
  User.redis_key #=> "users:redis:slave"
122
113
 
123
- **`key_pluralize_instances`** allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
114
+ **`pluralize_instances`** allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
124
115
 
125
- User.key_pluralize_instances false
116
+ :pluralize_instances => false
126
117
  user.redis_key #=> "user:redis"
127
118
 
128
119
 
129
- **key_plural** allows you to over-ride the default pluralize method with custom spelling
120
+ **plural** allows you to over-ride the default pluralize method with custom spelling
130
121
 
131
- User.key_plural "uzerz"
122
+ :plural => "uzerz"
132
123
  user.redis_key #=> "uzerz:redis"
133
124
 
134
- **key_case** allows you to specify the case of your key
125
+ **case** allows you to specify the case of your key
135
126
 
136
- User.key_case :upcase
127
+ :case => :upcase
137
128
  User.redis_key #=> "USER:REDIS"
138
129
 
139
130
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{keytar}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Schneems"]
@@ -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
@@ -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 :key_delimiter => key_delimiter,
191
- :key_order => key_order,
192
- :key_prefix => key_prefix,
193
- :key_suffix => key_suffix,
194
- :key_pluralize_instances => key_pluralize_instances,
195
- :key_case => key_case,
196
- :key_plural => key_plural,
197
- :key_unique => key_unique
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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keytar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Schneems