keytar 0.1.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/.DS_Store +0 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +28 -0
- data/README.md +173 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/keytar.rb +7 -0
- data/lib/keytar/key_builder.rb +105 -0
- data/license.txt +20 -0
- data/pkg/keytar-0.1.0.gem +0 -0
- data/spec/keytar/key_builder_spec.rb +137 -0
- data/spec/keytar/keytar_spec.rb +13 -0
- data/spec/keytar/spec_helper.rb +13 -0
- metadata +137 -0
data/.DS_Store
ADDED
Binary file
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.6)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rake (0.8.7)
|
12
|
+
rspec (2.5.0)
|
13
|
+
rspec-core (~> 2.5.0)
|
14
|
+
rspec-expectations (~> 2.5.0)
|
15
|
+
rspec-mocks (~> 2.5.0)
|
16
|
+
rspec-core (2.5.1)
|
17
|
+
rspec-expectations (2.5.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.5.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
activesupport
|
26
|
+
jeweler
|
27
|
+
rake
|
28
|
+
rspec (~> 2.5)
|
data/README.md
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
Keytar
|
2
|
+
======
|
3
|
+
|
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
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
Coming Soon
|
12
|
+
|
13
|
+
KeyBuilder
|
14
|
+
----------
|
15
|
+
|
16
|
+
Keytar is a Ruby on Rails wrapper for KeyBuilder. Use KeyBuilder to automatically generate keys based on class name instead of cluttering model definitions with tons of redundant key method declarations.
|
17
|
+
|
18
|
+
quit littering your code with junk like this:
|
19
|
+
|
20
|
+
def self.some_distributed_no_sql_datastore_key
|
21
|
+
"foo:some_distributed_no_sql_datastore"
|
22
|
+
end
|
23
|
+
|
24
|
+
Seriously, quit it
|
25
|
+
|
26
|
+
|
27
|
+
Example:
|
28
|
+
--------
|
29
|
+
|
30
|
+
Keytar in action
|
31
|
+
|
32
|
+
class User < ActiveRecord::Base
|
33
|
+
end
|
34
|
+
|
35
|
+
User.key #=> "user"
|
36
|
+
User.memcache_key #=> "user:memcache"
|
37
|
+
|
38
|
+
u = User.new
|
39
|
+
u.redis_key #=> "users:redis"
|
40
|
+
u.redis_key("some_arguement") #=> "users:redis:some_arguement"
|
41
|
+
|
42
|
+
u = User.create(:id => 2)
|
43
|
+
u.sweet_key #=> "users:sweet:2"
|
44
|
+
|
45
|
+
|
46
|
+
It's that simple
|
47
|
+
|
48
|
+
Config
|
49
|
+
------
|
50
|
+
|
51
|
+
There's a ton of configuration options. Call the below methods in your class to configure it's options.
|
52
|
+
|
53
|
+
class User < ActiveRecord::Base
|
54
|
+
key_delimiter ":"
|
55
|
+
key_order [:prefix, :base, :name, :unique, :args, :suffix]
|
56
|
+
key_prefix nil
|
57
|
+
key_suffix nil
|
58
|
+
key_pluralize_instances true
|
59
|
+
key_plural nil
|
60
|
+
key_case :downcase
|
61
|
+
key_unique "id"
|
62
|
+
end
|
63
|
+
|
64
|
+
Here is a run down of what each does
|
65
|
+
|
66
|
+
User.key_delimeter "|"
|
67
|
+
user.redis_key #=> "users|redis"
|
68
|
+
|
69
|
+
key_delimeter sets the separating argument in keys
|
70
|
+
|
71
|
+
User.key_order [:name, :base]
|
72
|
+
user.redis_key #=> "redis:users"
|
73
|
+
|
74
|
+
key_order sets the location of key parts, if a symbol is omitted, it will not show up in the final key
|
75
|
+
|
76
|
+
User.key_prefix "woot"
|
77
|
+
user.redis_key #=> "woot:users:redis"
|
78
|
+
|
79
|
+
key_prefix sets the a prefix to your key for that class
|
80
|
+
|
81
|
+
User.key_suffix "slave"
|
82
|
+
user.redis_key #=> "users:redis:slave"
|
83
|
+
|
84
|
+
key_suffix sets the a suffix to your key for that class
|
85
|
+
|
86
|
+
User.key_pluralize_instances false
|
87
|
+
user.redis_key #=> "user:redis"
|
88
|
+
|
89
|
+
key_pluralize_instances allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
|
90
|
+
|
91
|
+
User.key_plural "uzerz"
|
92
|
+
user.redis_key #=> "uzerz:redis"
|
93
|
+
|
94
|
+
key_plural allows you to over-ride the default pluralize method with custom spelling
|
95
|
+
|
96
|
+
User.key_case :upcase
|
97
|
+
user.redis_key #=> "USERS:REDIS"
|
98
|
+
|
99
|
+
key_case allows you to specify the case of your key
|
100
|
+
|
101
|
+
User.key_unique "username"
|
102
|
+
|
103
|
+
`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)
|
104
|
+
|
105
|
+
user = User.create(:username => "Schneems", :id => 9)
|
106
|
+
user.id #=> 9
|
107
|
+
user.redis_key #=> "users:redis:9"
|
108
|
+
|
109
|
+
User.key_unique("username")
|
110
|
+
user.redis_key #=> "users:redis:schneems"
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
Since this library is sooooo simple, here is a ASCII keytar for you. Thanks for checking it out.
|
118
|
+
|
119
|
+
,,,,
|
120
|
+
,,:::,
|
121
|
+
,,,,7::=
|
122
|
+
,:~?MOZN~
|
123
|
+
,,=~ONZDM
|
124
|
+
,,,~,NMOM+
|
125
|
+
:,,:~MNOM,
|
126
|
+
,,,:,,MO8M
|
127
|
+
:,,,,:: NO
|
128
|
+
,:,~=~+,,:~
|
129
|
+
,:::+:I:=::,
|
130
|
+
=?::::I::::
|
131
|
+
,~:,+7:::::~
|
132
|
+
~,,,,,,+~::: ,,,
|
133
|
+
,:,,,,,=,,,7~: ,::::,
|
134
|
+
,:,,:,,?~::=:,+=:,,,,,,,::::::
|
135
|
+
::::,,:,,NMZ,=,,+=::,::::+::::
|
136
|
+
~:,,,::,88=DNM:,:,:+~:::,MN~,~
|
137
|
+
,:,,:,,,+=+MM==8MZ,=::::::?=:~~
|
138
|
+
~,,: ,,=,7MN~OMM=?NM::~:$+:~:=
|
139
|
+
~:,:,:,~7~:==MM?+ZM8~7::I~:+:::
|
140
|
+
,:,,,,,~,:NM8:=~$MD?+M~::~~~~~~
|
141
|
+
~,:,, +,+DO=?MM~,=~NM8:::I+:::~
|
142
|
+
,~:,:,=:,:~+MM8=ZMD:~::::+:~::~
|
143
|
+
~:,:,:,,?DZ:?~ONM=+MM:+~:I?~:~
|
144
|
+
~~,,,~:,ZN=?MN~::~OMO~:NMM:,::~
|
145
|
+
,~:,:~,,==+ZM8+8MZ:::~=+8D+,===,
|
146
|
+
~:,~=,,=,$MD++MM~?MMO::ND8,===~
|
147
|
+
,:,:,,:=:~:==MMD=OMO~Z=~=+?:===:
|
148
|
+
~,:,,,=,:ZM8~=:=NN?+M+::I7+~==:
|
149
|
+
~:::,,=,+DN=?MM~,=~ZM8:~7~::~~=
|
150
|
+
,~::,:=,:~~~8MZ+OM8~,~::==::=~:,
|
151
|
+
~:,: =,,?D$~~~+MN=+NMO::$~~~~~=
|
152
|
+
~,,~,:,=+=DMZ~~~+NN==$,::?~~::=
|
153
|
+
,,:~,::=,~NN+IMM$:+=8D,:::~~+~=
|
154
|
+
~,::,::,=D8?OMZ??NN:~:::?I:~:~
|
155
|
+
:,:,:,:,,+~=MN+?MDZ+DM::+7::~~=
|
156
|
+
,::,,,~,:NN~~?~OM8+8MN:::N:~~:=,
|
157
|
+
:~,,:~,,$$+8MM~~~=MN==::=Z~~:~~
|
158
|
+
,:,::,,,~,+MN+I8M$~+~Z,:==~~~~~
|
159
|
+
:,,,,,,=I\~+~DM$=?MN::::::~+~+
|
160
|
+
~,::,,,=~=?M\~=~?MN7=O:::$~=:~,
|
161
|
+
:,~,,,=,~NN$+N\ :~:+MI::N:::~=
|
162
|
+
,:=:,,+,=DZ?DMN+7M\:==,:~::=~=
|
163
|
+
::::~::,::+MN+?DN7+N\,:~::=:=
|
164
|
+
::::::,~::,?:DMN+?MN~~ :::~::
|
165
|
+
:::::::,I:,~:+8NZ=,:=+I::~
|
166
|
+
,,:::::+:,,+:=$::$7::~
|
167
|
+
:,:::,I:,,,:?7=:~~
|
168
|
+
I:,:::::::$7I,:~
|
169
|
+
,::::~:,7:::
|
170
|
+
|
171
|
+
|
172
|
+
Copyright (c) 2011 Schneems. See LICENSE.txt for
|
173
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "keytar"
|
16
|
+
gem.homepage = "http://github.com/Schnems/keytar"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{A crazy simple library for building keys (in _key_ value store, not house keys) for Ruby on Rails}
|
19
|
+
gem.description = %Q{
|
20
|
+
Keytar is a Ruby on Rails wrapper for KeyBuilder.
|
21
|
+
Use KeyBuilder to automatically generate keys based on class name instead of cluttering model
|
22
|
+
definitions with tons of redundant key method declarations.
|
23
|
+
}
|
24
|
+
gem.email = "richard.schneeman@gmail.com"
|
25
|
+
gem.authors = ["Schneems"]
|
26
|
+
gem.add_development_dependency "rspec"
|
27
|
+
|
28
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
29
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
30
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
31
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
32
|
+
end
|
33
|
+
Jeweler::RubygemsDotOrgTasks.new
|
34
|
+
|
35
|
+
|
36
|
+
# require 'spec/rake/spectask'
|
37
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
38
|
+
# spec.libs << 'lib' << 'spec'
|
39
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
43
|
+
# spec.libs << 'lib' << 'spec'
|
44
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
45
|
+
# spec.rcov = true
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# task :default => :test
|
49
|
+
|
50
|
+
# require 'rake/rdoctask'
|
51
|
+
# Rake::RDocTask.new do |rdoc|
|
52
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
+
#
|
54
|
+
# rdoc.rdoc_dir = 'rdoc'
|
55
|
+
# rdoc.title = "keytar #{version}"
|
56
|
+
# rdoc.rdoc_files.include('README*')
|
57
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/keytar.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support/inflector' # used for pluralize
|
3
|
+
require 'active_support/core_ext/object/blank' # used for blank? and present?
|
4
|
+
|
5
|
+
module KeyBuilder
|
6
|
+
alias :original_method_missing :method_missing
|
7
|
+
|
8
|
+
DEFAULTS = {:key_delimiter => ":",
|
9
|
+
:key_order => [:prefix, :base, :name, :unique, :args, :suffix],
|
10
|
+
:key_prefix => nil,
|
11
|
+
:key_suffix => nil,
|
12
|
+
:key_pluralize_instances => true,
|
13
|
+
:key_case => :downcase,
|
14
|
+
:key_plural => nil,
|
15
|
+
:key_unique => "id"
|
16
|
+
}
|
17
|
+
|
18
|
+
def self.included(klass)
|
19
|
+
# setup method missing on class
|
20
|
+
klass.class_eval %{
|
21
|
+
extend KeyBuilder::Ext
|
22
|
+
# if method_missing doesn't already exist, aliasing and calling it will create an infinite loop
|
23
|
+
@@key_builder_jump_to_superclass = true unless klass.respond_to?("method_missing")
|
24
|
+
def self.method_missing(method_name, *args, &blk)
|
25
|
+
if method_name.to_s =~ /.*key$/
|
26
|
+
self.build_key(:base => self.to_s.downcase, :name => method_name, :args => args)
|
27
|
+
else
|
28
|
+
if @@key_builder_jump_to_superclass
|
29
|
+
superclass.method_missing(method_name, *args, &blk)
|
30
|
+
else
|
31
|
+
key_builder_alias_method_missing(method_name, *args, &blk)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
# class methods to be extended
|
39
|
+
module Ext
|
40
|
+
# creates class level getter and setter methods for the defaults for config
|
41
|
+
DEFAULTS.keys.each do |key|
|
42
|
+
eval %{
|
43
|
+
def #{key}(#{key}_input = :key_default)
|
44
|
+
@@#{key} = DEFAULTS[:#{key}] unless defined? @@#{key}
|
45
|
+
@@#{key} = #{key}_input unless #{key}_input == :key_default
|
46
|
+
return @@#{key}
|
47
|
+
end
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# Call KeyBuilder.build_key or Foo.build_key with options
|
53
|
+
# :base => self.to_s.downcase, :name => method_name, :args => args
|
54
|
+
def build_key(options = {})
|
55
|
+
key_hash = build_key_hash(options)
|
56
|
+
key_array = key_hash_to_ordered_array(key_hash)
|
57
|
+
return key_from_array(key_array)
|
58
|
+
end
|
59
|
+
|
60
|
+
# takes input options and turns to a hash, which can be sorted based on key
|
61
|
+
def build_key_hash(options)
|
62
|
+
options[:name] = options[:name].to_s.gsub(/(key|_key)/, '')
|
63
|
+
options.merge :prefix => self.key_prefix, :suffix => self.key_suffix
|
64
|
+
end
|
65
|
+
|
66
|
+
# orders the elements based on defaults or config
|
67
|
+
def key_hash_to_ordered_array(key_hash)
|
68
|
+
key_array ||= []
|
69
|
+
self.key_order.each do |key|
|
70
|
+
if key != :args
|
71
|
+
key_array << key_hash[key]
|
72
|
+
else
|
73
|
+
key_array << key_hash[key].map(&:to_s)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
return key_array
|
77
|
+
end
|
78
|
+
|
79
|
+
# applys a delimter and appropriate case to final key
|
80
|
+
def key_from_array(key_array)
|
81
|
+
key = key_array.flatten.reject {|item| item.blank? }.join(self.key_delimiter)
|
82
|
+
key = key.downcase if self.key_case == :downcase
|
83
|
+
key = key.upcase if self.key_case == :upcase
|
84
|
+
key
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# build_key method for instances by default class is pluralized to create different key
|
89
|
+
def build_key(method_name, *args)
|
90
|
+
base = self.class.to_s.downcase
|
91
|
+
base = self.class.key_plural||base.pluralize if self.class.key_pluralize_instances.present?
|
92
|
+
unique = eval("self.#{self.class.key_unique}") unless eval("self.#{self.class.key_unique}") == object_id
|
93
|
+
self.class.build_key(:base => base, :name => method_name, :args => args, :unique => unique)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
def method_missing(method_name, *args, &blk)
|
99
|
+
if method_name.to_s =~ /.*key$/
|
100
|
+
build_key(method_name, *args)
|
101
|
+
else
|
102
|
+
original_method_missing(method_name, *args, &blk)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/license.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Schneems
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Binary file
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Foo
|
4
|
+
include KeyBuilder
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
describe KeyBuilder do
|
9
|
+
|
10
|
+
describe 'class methods' do
|
11
|
+
it 'should respond to "key" method by returning downcase of class name' do
|
12
|
+
Foo.key.should == "foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should respond to "awesome_key" method by returning :class, :delimiter, :name' do
|
16
|
+
Foo.awesome_key.should == "foo:awesome"
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should respond to "awesome_key(number)" method by returning :class, :delimiter, :name, :delimiter, :arg' do
|
20
|
+
number = rand(100)
|
21
|
+
Foo.awesome_key(number).should == "foo:awesome:#{number}"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should call method_missing on a non-existant method' do
|
25
|
+
begin
|
26
|
+
Foo.thismethoddoesnotexist
|
27
|
+
rescue => ex
|
28
|
+
end
|
29
|
+
ex.class.should == NoMethodError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
describe 'instance methods' do
|
35
|
+
before(:each) do
|
36
|
+
@foo = Foo.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should respond to "key" method by returning pluralized downcase of class name' do
|
40
|
+
@foo.key.should == "foos"
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should respond to "awesome_key" method by returning :class, :delimiter, :name' do
|
44
|
+
@foo.awesome_key.should == "foos:awesome"
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should respond to "awesome_key(number)" method by returning :class, :delimiter, :name, :delimiter, :arg' do
|
48
|
+
number = rand(100)
|
49
|
+
@foo.awesome_key(number).should == "foos:awesome:#{number}"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should call method_missing on a non-existant method' do
|
53
|
+
begin
|
54
|
+
@foo.thismethoddoesnotexist
|
55
|
+
rescue => ex
|
56
|
+
end
|
57
|
+
ex.class.should == NoMethodError
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# test last
|
62
|
+
describe 'class configurations' do
|
63
|
+
after(:each) do
|
64
|
+
# todo find a better way of resetting all these values
|
65
|
+
Foo.key_delimiter KeyBuilder::DEFAULTS[:key_delimiter]
|
66
|
+
Foo.key_order KeyBuilder::DEFAULTS[:key_order]
|
67
|
+
Foo.key_prefix KeyBuilder::DEFAULTS[:key_prefix]
|
68
|
+
Foo.key_suffix KeyBuilder::DEFAULTS[:key_suffix]
|
69
|
+
Foo.key_pluralize_instances KeyBuilder::DEFAULTS[:key_pluralize_instances]
|
70
|
+
Foo.key_case KeyBuilder::DEFAULTS[:key_case]
|
71
|
+
Foo.key_plural KeyBuilder::DEFAULTS[:key_plural]
|
72
|
+
Foo.key_unique KeyBuilder::DEFAULTS[:key_unique]
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should change key_delimiter' do
|
76
|
+
key_delimiter = "|"
|
77
|
+
Foo.key_delimiter key_delimiter
|
78
|
+
Foo.key_delimiter.should == key_delimiter
|
79
|
+
Foo.awesome_key.should == "foo#{key_delimiter}awesome"
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
it 'should change key_order' do
|
84
|
+
order_array = [:prefix, :name, :unique, :base, :args, :suffix]
|
85
|
+
Foo.key_order order_array
|
86
|
+
Foo.key_order.should == order_array
|
87
|
+
Foo.awesome_key.should == "awesome:foo"
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should change key_prefix' do
|
91
|
+
key_prefix = "memcache"
|
92
|
+
Foo.key_prefix key_prefix
|
93
|
+
Foo.key_prefix.should == key_prefix
|
94
|
+
Foo.awesome_key.should == "#{key_prefix}:foo:awesome"
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should change key_suffix' do
|
98
|
+
key_suffix = "slave"
|
99
|
+
Foo.key_suffix key_suffix
|
100
|
+
Foo.key_suffix.should == key_suffix
|
101
|
+
Foo.awesome_key.should == "foo:awesome:#{key_suffix}"
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should change key_pluralize_instances' do
|
105
|
+
key_pluralize_instances = false
|
106
|
+
Foo.key_pluralize_instances key_pluralize_instances
|
107
|
+
Foo.key_pluralize_instances.should == key_pluralize_instances
|
108
|
+
foo = Foo.new
|
109
|
+
foo.awesome_key.should == "foo:awesome"
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should change key_case' do
|
113
|
+
key_case = :upcase
|
114
|
+
Foo.key_case key_case
|
115
|
+
Foo.key_case.should == key_case
|
116
|
+
Foo.awesome_key.should == "FOO:AWESOME"
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should change key_plural' do
|
120
|
+
key_plural = "fooz"
|
121
|
+
Foo.key_plural key_plural
|
122
|
+
Foo.key_plural.should == key_plural
|
123
|
+
foo = Foo.new
|
124
|
+
foo.awesome_key.should == "fooz:awesome"
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should change key_unique' do
|
128
|
+
Foo.class_eval { def timeish; (Time.now.to_i * 0.01).floor; end}
|
129
|
+
key_unique = :timeish
|
130
|
+
Foo.key_unique key_unique
|
131
|
+
Foo.key_unique.should == key_unique
|
132
|
+
foo = Foo.new
|
133
|
+
foo.awesome_key.should == "foos:awesome:#{foo.timeish}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class Bar < ActiveRecord::Base
|
3
|
+
end
|
4
|
+
|
5
|
+
describe Keytar do
|
6
|
+
describe 'requiring Keytar' do
|
7
|
+
it 'should load keybuilder into ActiveRecord::Base' do
|
8
|
+
describe Bar.ancestors do
|
9
|
+
it {should include( KeyBuilder)}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keytar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Schneems
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-19 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
name: activesupport
|
33
|
+
version_requirements: *id001
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
name: rake
|
47
|
+
version_requirements: *id002
|
48
|
+
prerelease: false
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
type: :development
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
name: jeweler
|
61
|
+
version_requirements: *id003
|
62
|
+
prerelease: false
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
type: :development
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
name: rspec
|
75
|
+
version_requirements: *id004
|
76
|
+
prerelease: false
|
77
|
+
description: "\n Keytar is a Ruby on Rails wrapper for KeyBuilder.\n Use KeyBuilder to automatically generate keys based on class name instead of cluttering model\n definitions with tons of redundant key method declarations.\n "
|
78
|
+
email: richard.schneeman@gmail.com
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files:
|
84
|
+
- README.md
|
85
|
+
files:
|
86
|
+
- .DS_Store
|
87
|
+
- Gemfile
|
88
|
+
- Gemfile.lock
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- VERSION
|
92
|
+
- lib/.DS_Store
|
93
|
+
- lib/keytar.rb
|
94
|
+
- lib/keytar/key_builder.rb
|
95
|
+
- license.txt
|
96
|
+
- pkg/keytar-0.1.0.gem
|
97
|
+
- spec/keytar/key_builder_spec.rb
|
98
|
+
- spec/keytar/keytar_spec.rb
|
99
|
+
- spec/keytar/spec_helper.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://github.com/Schnems/keytar
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.6.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: A crazy simple library for building keys (in _key_ value store, not house keys) for Ruby on Rails
|
134
|
+
test_files:
|
135
|
+
- spec/keytar/key_builder_spec.rb
|
136
|
+
- spec/keytar/keytar_spec.rb
|
137
|
+
- spec/keytar/spec_helper.rb
|