keytar 0.1.1 → 0.9.0
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/.rvmrc +19 -0
- data/Gemfile +5 -5
- data/Gemfile.lock +5 -5
- data/README.md +55 -43
- data/VERSION +1 -1
- data/keytar.gemspec +32 -15
- data/lib/keytar.rb +5 -2
- data/lib/keytar/key_builder.rb +25 -3
- data/pkg/keytar-0.1.1.gem +0 -0
- data/spec/keytar/key_builder_spec.rb +67 -1
- data/spec/keytar/keytar_spec.rb +40 -5
- data/vendor/cache/activemodel-3.0.6.gem +0 -0
- data/vendor/cache/activerecord-3.0.6.gem +0 -0
- data/vendor/cache/activesupport-3.0.6.gem +0 -0
- data/vendor/cache/arel-2.0.9.gem +0 -0
- data/vendor/cache/builder-2.1.2.gem +0 -0
- data/vendor/cache/diff-lcs-1.1.2.gem +0 -0
- data/vendor/cache/git-1.2.5.gem +0 -0
- data/vendor/cache/i18n-0.5.0.gem +0 -0
- data/vendor/cache/jeweler-1.5.2.gem +0 -0
- data/vendor/cache/rake-0.8.7.gem +0 -0
- data/vendor/cache/rspec-2.5.0.gem +0 -0
- data/vendor/cache/rspec-core-2.5.1.gem +0 -0
- data/vendor/cache/rspec-expectations-2.5.0.gem +0 -0
- data/vendor/cache/rspec-mocks-2.5.0.gem +0 -0
- data/vendor/cache/sqlite3-1.3.3.gem +0 -0
- data/vendor/cache/tzinfo-0.3.26.gem +0 -0
- metadata +43 -18
data/.rvmrc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
ruby_string="ree-1.8.7-2011.03"
|
4
|
+
gemset_name="keytar"
|
5
|
+
|
6
|
+
if rvm list strings | grep -q "${ruby_string}" ; then
|
7
|
+
|
8
|
+
rvm use "${ruby_string}@${gemset_name}" --create
|
9
|
+
|
10
|
+
# Complain if bundler isn't installed
|
11
|
+
if [[ -z "`gem which bundler 2>&1 | grep -v ERROR`" ]]; then
|
12
|
+
echo "You need bundler:"
|
13
|
+
echo ""
|
14
|
+
echo " gem install bundler"
|
15
|
+
echo ""
|
16
|
+
fi
|
17
|
+
else
|
18
|
+
echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into the project directory."
|
19
|
+
fi
|
data/Gemfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
group :development do
|
4
|
-
gem 'activerecord' ## not needed if you're just using KeyBuilder
|
5
|
-
gem 'activesupport' ## KeyBuilder
|
6
|
-
gem 'rake'
|
7
|
-
gem 'jeweler'
|
4
|
+
gem 'activerecord', '~>3.0.4' ## not needed if you're just using KeyBuilder
|
5
|
+
gem 'activesupport', '~>3.0.4' ## KeyBuilder relies on several helper methods, can be re-factored to not need this
|
6
|
+
gem 'rake', '~>0.8.7'
|
7
|
+
gem 'jeweler', '~>1.5.2'
|
8
8
|
end
|
9
9
|
|
10
10
|
group :test do
|
11
|
-
gem 'sqlite3'
|
11
|
+
gem 'sqlite3', '~> 1.3.3'
|
12
12
|
gem 'rspec', '~> 2.5'
|
13
13
|
end
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,41 +2,40 @@ Keytar
|
|
2
2
|
======
|
3
3
|
|
4
4
|
**1.** A keyboard that is designed to be played standing up, like a guitar.
|
5
|
-
**2.** A crazy simple ruby-on-rails library for making re-usable keys
|
5
|
+
**2.** A crazy simple ruby-on-rails library for making re-usable keys (the kind you use in key/value stores)
|
6
6
|
|
7
7
|
KeyBuilder
|
8
8
|
----------
|
9
9
|
|
10
|
-
Keytar is
|
10
|
+
Keytar is an amazingly easy way to auto-magically 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 automatically generates keys based on class name instead of cluttering model definitions with tons of redundant key method declarations.
|
11
11
|
|
12
|
-
|
12
|
+
___quit___ littering your code with junk like this:
|
13
13
|
|
14
|
+
class User
|
14
15
|
def some_distributed_no_sql_datastore_key
|
15
16
|
"foos:some_distributed_no_sql_datastore:#{self.id}"
|
16
17
|
end
|
17
|
-
|
18
|
-
Seriously, quit it
|
19
|
-
|
18
|
+
end
|
20
19
|
|
20
|
+
Seriously, ___quit it___!
|
21
21
|
|
22
22
|
|
23
23
|
Installation
|
24
24
|
------------
|
25
|
-
|
26
|
-
|
27
|
-
in your Gemfile add
|
25
|
+
In your Ruby on Rails Gemfile add
|
28
26
|
|
29
27
|
gem 'keytar'
|
30
28
|
|
31
|
-
|
29
|
+
then run
|
32
30
|
|
33
|
-
|
34
|
-
--------
|
31
|
+
bundle install
|
35
32
|
|
36
|
-
Keytar in
|
33
|
+
now, you're good to go. Not using RoR? No worries, just drop `include Keytar` in any Ruby model you want.
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
|
36
|
+
Example:
|
37
|
+
--------
|
38
|
+
keytar auto-magically generates keys using method names ending in `"_key"` or simply "key".
|
40
39
|
|
41
40
|
User.key #=> "user"
|
42
41
|
User.memcache_key #=> "user:memcache"
|
@@ -49,74 +48,81 @@ Keytar in action
|
|
49
48
|
u.sweet_key #=> "users:sweet:2"
|
50
49
|
|
51
50
|
|
51
|
+
|
52
52
|
It's that simple
|
53
53
|
|
54
54
|
Config
|
55
55
|
------
|
56
56
|
|
57
|
-
|
57
|
+
These options can be configured by passing in a hash to keyfig:
|
58
|
+
|
59
|
+
class User < ActiveRecord::Base
|
60
|
+
keyfig :key_delimiter => ":", :key_order => [:unique, :suffix], :key_prefix => "before"
|
61
|
+
end
|
62
|
+
|
63
|
+
Or by calling class methods
|
58
64
|
|
59
65
|
class User < ActiveRecord::Base
|
60
66
|
key_delimiter ":"
|
61
67
|
key_order [:prefix, :base, :name, :unique, :args, :suffix]
|
62
68
|
key_prefix nil
|
63
|
-
key_suffix nil
|
64
|
-
key_pluralize_instances true
|
65
|
-
key_plural nil
|
66
|
-
key_case :downcase
|
67
|
-
key_unique "id"
|
68
69
|
end
|
69
70
|
|
71
|
+
Config Options Breakdown
|
72
|
+
------------------------
|
70
73
|
Here is a run down of what each does
|
71
74
|
|
75
|
+
**key_delimeter** sets the separating argument in keys
|
76
|
+
|
72
77
|
User.key_delimeter "|"
|
73
78
|
user.redis_key #=> "users|redis"
|
74
79
|
|
75
|
-
|
80
|
+
|
81
|
+
**key_order** sets the location of key parts, if a symbol is omitted, it will not show up in the final key
|
76
82
|
|
77
83
|
User.key_order [:name, :base]
|
78
84
|
user.redis_key #=> "redis:users"
|
79
|
-
|
80
|
-
key_order sets the location of key parts, if a symbol is omitted, it will not show up in the final key
|
81
85
|
|
86
|
+
**key_unique** sets the unique value of the instance that is used to build the key
|
87
|
+
|
88
|
+
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)
|
89
|
+
|
90
|
+
user = User.create(:username => "Schneems", :id => 9)
|
91
|
+
user.id #=> 9
|
92
|
+
user.redis_key #=> "users:redis:9"
|
93
|
+
|
94
|
+
User.key_unique("username")
|
95
|
+
user.redis_key #=> "users:redis:schneems"
|
96
|
+
|
97
|
+
**key_prefix** sets the a prefix to your key for that class
|
98
|
+
|
82
99
|
User.key_prefix "woot"
|
83
100
|
user.redis_key #=> "woot:users:redis"
|
84
101
|
|
85
|
-
|
102
|
+
**key_suffix** sets the a suffix to your key for that class
|
86
103
|
|
87
104
|
User.key_suffix "slave"
|
88
105
|
user.redis_key #=> "users:redis:slave"
|
89
106
|
|
90
|
-
|
107
|
+
**`key_pluralize_instances`** allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
|
91
108
|
|
92
109
|
User.key_pluralize_instances false
|
93
110
|
user.redis_key #=> "user:redis"
|
94
111
|
|
95
|
-
|
112
|
+
|
113
|
+
**key_plural** allows you to over-ride the default pluralize method with custom spelling
|
96
114
|
|
97
115
|
User.key_plural "uzerz"
|
98
116
|
user.redis_key #=> "uzerz:redis"
|
99
117
|
|
100
|
-
|
118
|
+
**key_case** allows you to specify the case of your key
|
101
119
|
|
102
120
|
User.key_case :upcase
|
103
121
|
user.redis_key #=> "USERS:REDIS"
|
104
122
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
`key_unique`: 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)
|
110
|
-
|
111
|
-
user = User.create(:username => "Schneems", :id => 9)
|
112
|
-
user.id #=> 9
|
113
|
-
user.redis_key #=> "users:redis:9"
|
114
|
-
|
115
|
-
User.key_unique("username")
|
116
|
-
user.redis_key #=> "users:redis:schneems"
|
117
|
-
|
118
|
-
|
119
|
-
|
123
|
+
**`key_cache_methods`** will let you toggle whether or not keytar defines your key methods after being called. If you're calling
|
124
|
+
these methods over and over, this can give you a speed boost, however there is overhead associated with defining methods. The default
|
125
|
+
is on, however try it both ways on your app run some benchmarks and see what works the best.
|
120
126
|
|
121
127
|
|
122
128
|
|
@@ -175,5 +181,11 @@ Since this library is sooooo simple, here is a ASCII keytar for you. Thanks for
|
|
175
181
|
,::::~:,7:::
|
176
182
|
|
177
183
|
|
184
|
+
Contribution
|
185
|
+
============
|
186
|
+
|
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.
|
188
|
+
|
189
|
+
|
178
190
|
Copyright (c) 2011 Schneems. See LICENSE.txt for
|
179
191
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.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 = "0.
|
8
|
+
s.version = "0.9.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-
|
12
|
+
s.date = %q{2011-05-08}
|
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
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
]
|
22
22
|
s.files = [
|
23
23
|
".DS_Store",
|
24
|
+
".rvmrc",
|
24
25
|
"Gemfile",
|
25
26
|
"Gemfile.lock",
|
26
27
|
"README.md",
|
@@ -36,7 +37,23 @@ Gem::Specification.new do |s|
|
|
36
37
|
"pkg/keytar-0.1.1.gem",
|
37
38
|
"spec/keytar/key_builder_spec.rb",
|
38
39
|
"spec/keytar/keytar_spec.rb",
|
39
|
-
"spec/keytar/spec_helper.rb"
|
40
|
+
"spec/keytar/spec_helper.rb",
|
41
|
+
"vendor/cache/activemodel-3.0.6.gem",
|
42
|
+
"vendor/cache/activerecord-3.0.6.gem",
|
43
|
+
"vendor/cache/activesupport-3.0.6.gem",
|
44
|
+
"vendor/cache/arel-2.0.9.gem",
|
45
|
+
"vendor/cache/builder-2.1.2.gem",
|
46
|
+
"vendor/cache/diff-lcs-1.1.2.gem",
|
47
|
+
"vendor/cache/git-1.2.5.gem",
|
48
|
+
"vendor/cache/i18n-0.5.0.gem",
|
49
|
+
"vendor/cache/jeweler-1.5.2.gem",
|
50
|
+
"vendor/cache/rake-0.8.7.gem",
|
51
|
+
"vendor/cache/rspec-2.5.0.gem",
|
52
|
+
"vendor/cache/rspec-core-2.5.1.gem",
|
53
|
+
"vendor/cache/rspec-expectations-2.5.0.gem",
|
54
|
+
"vendor/cache/rspec-mocks-2.5.0.gem",
|
55
|
+
"vendor/cache/sqlite3-1.3.3.gem",
|
56
|
+
"vendor/cache/tzinfo-0.3.26.gem"
|
40
57
|
]
|
41
58
|
s.homepage = %q{http://github.com/Schnems/keytar}
|
42
59
|
s.licenses = ["MIT"]
|
@@ -53,23 +70,23 @@ Gem::Specification.new do |s|
|
|
53
70
|
s.specification_version = 3
|
54
71
|
|
55
72
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
-
s.add_development_dependency(%q<activerecord>, ["
|
57
|
-
s.add_development_dependency(%q<activesupport>, ["
|
58
|
-
s.add_development_dependency(%q<rake>, ["
|
59
|
-
s.add_development_dependency(%q<jeweler>, ["
|
73
|
+
s.add_development_dependency(%q<activerecord>, ["~> 3.0.4"])
|
74
|
+
s.add_development_dependency(%q<activesupport>, ["~> 3.0.4"])
|
75
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
76
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
77
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
61
78
|
else
|
62
|
-
s.add_dependency(%q<activerecord>, ["
|
63
|
-
s.add_dependency(%q<activesupport>, ["
|
64
|
-
s.add_dependency(%q<rake>, ["
|
65
|
-
s.add_dependency(%q<jeweler>, ["
|
79
|
+
s.add_dependency(%q<activerecord>, ["~> 3.0.4"])
|
80
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
81
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
82
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
83
|
s.add_dependency(%q<rspec>, [">= 0"])
|
67
84
|
end
|
68
85
|
else
|
69
|
-
s.add_dependency(%q<activerecord>, ["
|
70
|
-
s.add_dependency(%q<activesupport>, ["
|
71
|
-
s.add_dependency(%q<rake>, ["
|
72
|
-
s.add_dependency(%q<jeweler>, ["
|
86
|
+
s.add_dependency(%q<activerecord>, ["~> 3.0.4"])
|
87
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
88
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
89
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
73
90
|
s.add_dependency(%q<rspec>, [">= 0"])
|
74
91
|
end
|
75
92
|
end
|
data/lib/keytar.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'active_record'
|
2
|
+
begin; require 'active_record'; rescue; end
|
3
3
|
|
4
4
|
module Keytar
|
5
5
|
autoload :KeyBuilder, 'keytar/key_builder'
|
6
|
-
ActiveRecord::Base.class_eval
|
6
|
+
ActiveRecord::Base.class_eval { include KeyBuilder } if defined?(ActiveRecord::Base)
|
7
|
+
def self.included(klass)
|
8
|
+
klass.class_eval {include KeyBuilder}
|
9
|
+
end
|
7
10
|
end
|
data/lib/keytar/key_builder.rb
CHANGED
@@ -12,12 +12,13 @@ module KeyBuilder
|
|
12
12
|
:key_pluralize_instances => true,
|
13
13
|
:key_case => :downcase,
|
14
14
|
:key_plural => nil,
|
15
|
-
:key_unique => "id"
|
15
|
+
:key_unique => "id",
|
16
|
+
:key_cache_methods => true
|
16
17
|
}
|
17
18
|
|
18
19
|
def self.included(klass)
|
19
20
|
# setup method missing on class
|
20
|
-
klass.class_eval
|
21
|
+
klass.class_eval do
|
21
22
|
extend KeyBuilder::Ext
|
22
23
|
# if method_missing doesn't already exist, aliasing and calling it will create an infinite loop
|
23
24
|
@@key_builder_jump_to_superclass = true
|
@@ -28,6 +29,14 @@ module KeyBuilder
|
|
28
29
|
|
29
30
|
def self.method_missing(method_name, *args, &blk)
|
30
31
|
if method_name.to_s =~ /.*key$/
|
32
|
+
## Performance: define method so we can skip method_missing next time
|
33
|
+
if key_cache_methods
|
34
|
+
(class << self;self ;end).instance_eval do
|
35
|
+
define_method(method_name) do |*args|
|
36
|
+
build_key(:base => self.to_s.downcase, :name => method_name, :args => args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
31
40
|
self.build_key(:base => self.to_s.downcase, :name => method_name, :args => args)
|
32
41
|
else
|
33
42
|
if @@key_builder_jump_to_superclass
|
@@ -37,7 +46,7 @@ module KeyBuilder
|
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
40
|
-
|
49
|
+
end
|
41
50
|
end
|
42
51
|
|
43
52
|
# class methods to be extended
|
@@ -53,6 +62,11 @@ module KeyBuilder
|
|
53
62
|
}
|
54
63
|
end
|
55
64
|
|
65
|
+
def keyfig(options = {})
|
66
|
+
options.keys.each do |key|
|
67
|
+
eval("@@#{key} = options[key]") if key.to_s =~ /^key_.*/
|
68
|
+
end
|
69
|
+
end
|
56
70
|
|
57
71
|
# Call KeyBuilder.build_key or Foo.build_key with options
|
58
72
|
# :base => self.to_s.downcase, :name => method_name, :args => args
|
@@ -102,6 +116,14 @@ module KeyBuilder
|
|
102
116
|
|
103
117
|
def method_missing(method_name, *args, &blk)
|
104
118
|
if method_name.to_s =~ /.*key$/
|
119
|
+
## Performance: define method so we can skip method_missing next time
|
120
|
+
if self.class.key_cache_methods
|
121
|
+
self.class.instance_eval do
|
122
|
+
define_method(method_name) do |*args|
|
123
|
+
build_key(method_name, *args)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
105
127
|
build_key(method_name, *args)
|
106
128
|
else
|
107
129
|
original_method_missing(method_name, *args, &blk)
|
data/pkg/keytar-0.1.1.gem
CHANGED
Binary file
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
2
3
|
|
3
4
|
class Foo
|
4
5
|
include KeyBuilder
|
@@ -21,6 +22,15 @@ describe KeyBuilder do
|
|
21
22
|
Foo.awesome_key(number).should == "foo:awesome:#{number}"
|
22
23
|
end
|
23
24
|
|
25
|
+
it 'should dynamically define a class method capeable of producing different keys' do
|
26
|
+
key1 = Foo.define_method_time_test_key(1)
|
27
|
+
key2 = Foo.define_method_time_test_key(2)
|
28
|
+
Foo.respond_to?(:define_method_time_test_key).should be_true
|
29
|
+
key2.should_not == key1
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
24
34
|
it 'should call method_missing on a non-existant method' do
|
25
35
|
begin
|
26
36
|
Foo.thismethoddoesnotexist
|
@@ -49,6 +59,20 @@ describe KeyBuilder do
|
|
49
59
|
@foo.awesome_key(number).should == "foos:awesome:#{number}"
|
50
60
|
end
|
51
61
|
|
62
|
+
it 'should dynamically define an instance method capeable of producing different keys' do
|
63
|
+
key1 = @foo.define_method_time_test_key(1)
|
64
|
+
key2 = @foo.define_method_time_test_key(2)
|
65
|
+
@foo.respond_to?(:define_method_time_test_key).should be_true
|
66
|
+
key2.should_not == key1
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should dynamically define an instance method capeable of producing different keys' do
|
70
|
+
key1 = @foo.define_method_time_test_key(1)
|
71
|
+
key2 = @foo.define_method_time_test_key(2)
|
72
|
+
@foo.respond_to?(:define_method_time_test_key).should be_true
|
73
|
+
key2.should_not == key1
|
74
|
+
end
|
75
|
+
|
52
76
|
it 'should call method_missing on a non-existant method' do
|
53
77
|
begin
|
54
78
|
@foo.thismethoddoesnotexist
|
@@ -70,6 +94,7 @@ describe KeyBuilder do
|
|
70
94
|
Foo.key_case KeyBuilder::DEFAULTS[:key_case]
|
71
95
|
Foo.key_plural KeyBuilder::DEFAULTS[:key_plural]
|
72
96
|
Foo.key_unique KeyBuilder::DEFAULTS[:key_unique]
|
97
|
+
Foo.key_cache_methods KeyBuilder::DEFAULTS[:key_cache_methods]
|
73
98
|
end
|
74
99
|
|
75
100
|
it 'should change key_delimiter' do
|
@@ -132,6 +157,47 @@ describe KeyBuilder do
|
|
132
157
|
foo = Foo.new
|
133
158
|
foo.awesome_key.should == "foos:awesome:#{foo.timeish}"
|
134
159
|
end
|
160
|
+
|
161
|
+
# todo move tests and assertsions to seperate describe and it blocks
|
162
|
+
it 'should allow all configurations to be set using a hash' do
|
163
|
+
# variables
|
164
|
+
key_delimiter = "/"
|
165
|
+
key_order = [:prefix, :base, :suffix]
|
166
|
+
key_prefix = "before"
|
167
|
+
key_suffix = "after"
|
168
|
+
key_pluralize_instances = false
|
169
|
+
key_case = :upcase
|
170
|
+
key_plural = "zoosk"
|
171
|
+
key_unique = "doesn-t_apply_to_instance_methods"
|
172
|
+
key_cache_methods = false
|
173
|
+
# config
|
174
|
+
Foo.keyfig :key_delimiter => key_delimiter,
|
175
|
+
:key_order => key_order,
|
176
|
+
:key_prefix => key_prefix,
|
177
|
+
:key_suffix => key_suffix,
|
178
|
+
:key_pluralize_instances => key_pluralize_instances,
|
179
|
+
:key_case => key_case,
|
180
|
+
:key_plural => key_plural,
|
181
|
+
:key_unique => key_unique,
|
182
|
+
:key_cache_methods => key_cache_methods
|
183
|
+
# assertions
|
184
|
+
Foo.key_delimiter.should == key_delimiter
|
185
|
+
Foo.key_order.should == key_order
|
186
|
+
Foo.key_prefix.should == key_prefix
|
187
|
+
Foo.key_suffix.should == key_suffix
|
188
|
+
Foo.key_pluralize_instances.should == key_pluralize_instances
|
189
|
+
Foo.key_case.should == key_case
|
190
|
+
Foo.key_plural.should == key_plural
|
191
|
+
Foo.key_unique.should == key_unique
|
192
|
+
Foo.key_cache_methods == key_cache_methods
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'should change key_cache_methods' do
|
196
|
+
Foo.key_cache_methods false
|
197
|
+
key1 = Foo.config_define_method_time_test_key(1)
|
198
|
+
Foo.respond_to?(:config_define_method_time_test_key).should be_false
|
199
|
+
end
|
200
|
+
|
135
201
|
end
|
136
202
|
|
137
203
|
end
|
data/spec/keytar/keytar_spec.rb
CHANGED
@@ -1,31 +1,66 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
## Gives us ActiveRecord backed model Bar that we can test instances of
|
3
3
|
ActiveRecord::Base.establish_connection(
|
4
4
|
:adapter => "sqlite3",
|
5
5
|
:database => ":memory:",
|
6
6
|
:host => 'localhost')
|
7
|
-
ActiveRecord::Migrator.migrate('../../db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
8
|
-
## Gives us ActiveRecord backed model Bar that we can test instances of
|
9
7
|
|
8
|
+
## Gives us ActiveRecord backed model Bar that we can test instances of
|
9
|
+
ActiveRecord::Migrator.migrate(
|
10
|
+
File.expand_path(File.dirname(__FILE__) + "../../../db/migrate") ,
|
11
|
+
ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
10
12
|
|
11
13
|
class Bar < ActiveRecord::Base
|
12
14
|
|
13
15
|
end
|
14
16
|
|
17
|
+
class BarNonActiveRecord
|
18
|
+
|
19
|
+
end
|
20
|
+
|
15
21
|
|
16
22
|
describe Keytar do
|
17
23
|
describe 'requiring Keytar' do
|
18
|
-
it 'should load keybuilder into ActiveRecord::Base' do
|
24
|
+
it 'should load keybuilder into ActiveRecord::Base if defined' do
|
19
25
|
describe Bar.ancestors do
|
20
26
|
it {should include( KeyBuilder)}
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
24
|
-
it 'should ' do
|
30
|
+
it 'should allow ActiveRecord based objects to use their unique identifiers' do
|
25
31
|
name = "notblank"
|
26
32
|
b = Bar.create(:name => name)
|
27
33
|
b.name.should == name
|
28
34
|
b.awesome_key.should == "bars:awesome:#{b.id}"
|
29
35
|
end
|
30
36
|
end
|
37
|
+
|
38
|
+
describe 'requiring Keytar with ActiveRecord undefined' do
|
39
|
+
before do
|
40
|
+
begin; Object.send(:remove_const, "ActiveRecord"); rescue NameError; end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does not automatically add KeyBuilder to the class' do
|
44
|
+
describe BarNonActiveRecord.ancestors do
|
45
|
+
it {should_not include( KeyBuilder)}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'allows non ActiveRecord based classes to use keytar directly' do
|
50
|
+
it 'includes keybuilder when it is included' do
|
51
|
+
BarNonActiveRecord.class_eval do
|
52
|
+
include Keytar
|
53
|
+
end
|
54
|
+
describe BarNonActiveRecord.ancestors do
|
55
|
+
it {should include( KeyBuilder)}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should allow ActiveRecord based objects to use their unique identifiers' do
|
60
|
+
BarNonActiveRecord.awesome_key.should == "barnonactiverecord:awesome"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
31
66
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
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: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.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-
|
18
|
+
date: 2011-05-08 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -23,12 +23,14 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 15
|
29
29
|
segments:
|
30
|
+
- 3
|
30
31
|
- 0
|
31
|
-
|
32
|
+
- 4
|
33
|
+
version: 3.0.4
|
32
34
|
name: activerecord
|
33
35
|
version_requirements: *id001
|
34
36
|
prerelease: false
|
@@ -37,12 +39,14 @@ dependencies:
|
|
37
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
40
|
none: false
|
39
41
|
requirements:
|
40
|
-
- -
|
42
|
+
- - ~>
|
41
43
|
- !ruby/object:Gem::Version
|
42
|
-
hash:
|
44
|
+
hash: 15
|
43
45
|
segments:
|
46
|
+
- 3
|
44
47
|
- 0
|
45
|
-
|
48
|
+
- 4
|
49
|
+
version: 3.0.4
|
46
50
|
name: activesupport
|
47
51
|
version_requirements: *id002
|
48
52
|
prerelease: false
|
@@ -51,12 +55,14 @@ dependencies:
|
|
51
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
56
|
none: false
|
53
57
|
requirements:
|
54
|
-
- -
|
58
|
+
- - ~>
|
55
59
|
- !ruby/object:Gem::Version
|
56
|
-
hash:
|
60
|
+
hash: 49
|
57
61
|
segments:
|
58
62
|
- 0
|
59
|
-
|
63
|
+
- 8
|
64
|
+
- 7
|
65
|
+
version: 0.8.7
|
60
66
|
name: rake
|
61
67
|
version_requirements: *id003
|
62
68
|
prerelease: false
|
@@ -65,12 +71,14 @@ dependencies:
|
|
65
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
66
72
|
none: false
|
67
73
|
requirements:
|
68
|
-
- -
|
74
|
+
- - ~>
|
69
75
|
- !ruby/object:Gem::Version
|
70
|
-
hash:
|
76
|
+
hash: 7
|
71
77
|
segments:
|
72
|
-
-
|
73
|
-
|
78
|
+
- 1
|
79
|
+
- 5
|
80
|
+
- 2
|
81
|
+
version: 1.5.2
|
74
82
|
name: jeweler
|
75
83
|
version_requirements: *id004
|
76
84
|
prerelease: false
|
@@ -98,6 +106,7 @@ extra_rdoc_files:
|
|
98
106
|
- README.md
|
99
107
|
files:
|
100
108
|
- .DS_Store
|
109
|
+
- .rvmrc
|
101
110
|
- Gemfile
|
102
111
|
- Gemfile.lock
|
103
112
|
- README.md
|
@@ -114,6 +123,22 @@ files:
|
|
114
123
|
- spec/keytar/key_builder_spec.rb
|
115
124
|
- spec/keytar/keytar_spec.rb
|
116
125
|
- spec/keytar/spec_helper.rb
|
126
|
+
- vendor/cache/activemodel-3.0.6.gem
|
127
|
+
- vendor/cache/activerecord-3.0.6.gem
|
128
|
+
- vendor/cache/activesupport-3.0.6.gem
|
129
|
+
- vendor/cache/arel-2.0.9.gem
|
130
|
+
- vendor/cache/builder-2.1.2.gem
|
131
|
+
- vendor/cache/diff-lcs-1.1.2.gem
|
132
|
+
- vendor/cache/git-1.2.5.gem
|
133
|
+
- vendor/cache/i18n-0.5.0.gem
|
134
|
+
- vendor/cache/jeweler-1.5.2.gem
|
135
|
+
- vendor/cache/rake-0.8.7.gem
|
136
|
+
- vendor/cache/rspec-2.5.0.gem
|
137
|
+
- vendor/cache/rspec-core-2.5.1.gem
|
138
|
+
- vendor/cache/rspec-expectations-2.5.0.gem
|
139
|
+
- vendor/cache/rspec-mocks-2.5.0.gem
|
140
|
+
- vendor/cache/sqlite3-1.3.3.gem
|
141
|
+
- vendor/cache/tzinfo-0.3.26.gem
|
117
142
|
has_rdoc: true
|
118
143
|
homepage: http://github.com/Schnems/keytar
|
119
144
|
licenses:
|