keytar 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require 'autotest/growl'
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/Gemfile CHANGED
@@ -1,10 +1,11 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- group :development do
3
+ group :development, :test do
4
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
5
  gem 'rake', '~>0.8.7'
7
6
  gem 'jeweler', '~>1.5.2'
7
+ gem "autotest-standalone"
8
+ gem "autotest-growl"
8
9
  end
9
10
 
10
11
  group :test do
data/README.md CHANGED
@@ -12,8 +12,8 @@ Keytar is an amazingly easy way generate keys for all of your NOSQL key needs. A
12
12
  ___quit___ littering your code with junk like this:
13
13
 
14
14
  class User
15
- def some_distributed_no_sql_datastore_key
16
- "foos:some_distributed_no_sql_datastore:#{self.id}"
15
+ def some_key_for_a_distributed_no_sql_datastore_key
16
+ "foos:some_key_for_a_distributed_no_sql_datastore_key:#{self.id}"
17
17
  end
18
18
  end
19
19
 
@@ -38,11 +38,11 @@ Example:
38
38
  keytar auto-magically generates keys using method names ending in `"_key"` or simply "key"
39
39
 
40
40
  User.key #=> "user"
41
- User.memcache_key #=> "user:memcache"
41
+ User.friends_key #=> "user:friends"
42
42
 
43
43
  u = User.new
44
- u.redis_key #=> "users:redis"
45
- u.redis_key("some_argument") #=> "users:redis:some_argument"
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
46
 
47
47
  u = User.create(:id => 2)
48
48
  u.sweet_key #=> "users:sweet:2"
@@ -58,7 +58,7 @@ Keys can be pre-defined and configured on a per key basis by calling **define\_k
58
58
  class User
59
59
  include Keytar
60
60
  define_keys [:friend_ids, :email_subscriptions, :news_feed], :delimiter => "|", :version => "v2"
61
- define_keys :cassandra, :delimiter => "/", :version => 3, :key_prefix => "lol"
61
+ define_keys :favorite_spots, :delimiter => "/", :version => 3, :key_prefix => "lol"
62
62
  end
63
63
 
64
64
  User.respond_to? :friend_ids_key #=> true
@@ -67,65 +67,66 @@ Keys can be pre-defined and configured on a per key basis by calling **define\_k
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
- global 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 :delimiter => ":", :order => [:unique, :suffix], :prefix => "before"
74
+ key_config :delimiter => "/", :suffix => "after"
75
+ define_keys :ignored_ids
75
76
  end
76
77
 
78
+ User.ignored_ids_key #=> "user/ignored_ids/after"
79
+
77
80
  Configuration Options Breakdown
78
81
  ------------------------
79
82
  Here is a run down of what each does
80
83
 
81
84
  **delimiter** sets the separating argument in keys
82
85
 
83
- :delimiter => "|"
84
- user.redis_key #=> "users|redis"
86
+ define_keys :favorite_spots, :delimiter => "|"
87
+ User.favorite_spots_key #=> "user|favorite_spots"
85
88
 
86
89
 
87
- **order** sets the location of key parts, if a symbol is omitted, it will not show up in the final key
90
+ **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)
88
91
 
89
- :key_order =>[:name, :base]
90
- user.redis_key #=> "redis:users"
92
+ define_keys :favorite_spots, :order => [:name, :base]
93
+ User.favorite_spots_key #=> "favorite_spots:user:1"
91
94
 
92
95
  **unique** sets the unique value of the instance that is used to build the key
93
96
 
94
97
  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)
95
98
 
96
- user = User.create(:username => "Schneems", :id => 9)
97
- user.id #=> 9
98
- user.redis_key #=> "users:redis:9"
99
+ User.create(:username => "Schneems", :id => 9)
100
+ User.find(9).favorite_spots_key #=> "users:favorite_spots:9"
99
101
 
100
- :unique => "username"
101
- user.username #=> "schneems"
102
- user.redis_key #=> "users:redis:schneems"
102
+ define_keys :favorite_spots, :unique => "username"
103
+ User.find(9).favorite_spots_key #=> "users:favorite_spots:schneems"
103
104
 
104
105
  **prefix** adds some text to the beginning of your key for that class
105
106
 
106
- :prefix => "woot"
107
- User.redis_key #=> "woot:users:redis"
107
+ define_keys :favorite_spots, :prefix => "woot"
108
+ User.favorite_spots_key #=> "woot:user:favorite_spots"
108
109
 
109
110
  **suffix** adds some text to the end of your key for that class
110
111
 
111
- :suffix => "slave"
112
- User.redis_key #=> "users:redis:slave"
112
+ define_keys :favorite_spots, :suffix => "pow"
113
+ User.favorite_spots_key #=> "user:favorite_spots:pow"
113
114
 
114
115
  **`pluralize_instances`** allows you to toggle pluralizing instance keys (note the 's' in 'users' is not there)
115
116
 
116
- :pluralize_instances => false
117
- user.redis_key #=> "user:redis"
117
+ define_keys :favorite_spots, :pluralize_instances => false
118
+ User.find(1).favorite_spots_key #=> "user:favorite_spots:1"
118
119
 
119
120
 
120
121
  **plural** allows you to over-ride the default pluralize method with custom spelling
121
122
 
122
- :plural => "uzerz"
123
- user.redis_key #=> "uzerz:redis"
123
+ define_keys :favorite_spots, :plural => "uzerz"
124
+ User.find(1).favorite_spots_key #=> "uzerz:favorite_spots:1"
124
125
 
125
126
  **case** allows you to specify the case of your key
126
127
 
127
- :case => :upcase
128
- User.redis_key #=> "USER:REDIS"
128
+ define_keys :favorite_spots, :case => :upcase
129
+ User.favorite_spots_key #=> "USER:REDIS"
129
130
 
130
131
 
131
132
  Since this library is sooooo simple, here is a ASCII keytar for you. Thanks for checking it out.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{keytar}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.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-05-16}
12
+ s.date = %q{2011-06-20}
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
@@ -20,19 +20,23 @@ Gem::Specification.new do |s|
20
20
  "README.md"
21
21
  ]
22
22
  s.files = [
23
+ ".autotest",
24
+ ".rspec",
23
25
  ".rvmrc",
24
26
  "Gemfile",
25
27
  "README.md",
26
28
  "Rakefile",
27
29
  "VERSION",
30
+ "autotest/discover.rb",
28
31
  "keytar.gemspec",
29
32
  "lib/.DS_Store",
30
33
  "lib/keytar.rb",
31
34
  "lib/keytar/key_builder.rb",
35
+ "lib/keytar/key_utility.rb",
32
36
  "license.txt",
33
37
  "spec/keytar/key_builder_spec.rb",
34
38
  "spec/keytar/keytar_spec.rb",
35
- "spec/keytar/spec_helper.rb"
39
+ "spec/spec_helper.rb"
36
40
  ]
37
41
  s.homepage = %q{http://github.com/Schnems/keytar}
38
42
  s.licenses = ["MIT"]
@@ -42,7 +46,7 @@ Gem::Specification.new do |s|
42
46
  s.test_files = [
43
47
  "spec/keytar/key_builder_spec.rb",
44
48
  "spec/keytar/keytar_spec.rb",
45
- "spec/keytar/spec_helper.rb"
49
+ "spec/spec_helper.rb"
46
50
  ]
47
51
 
48
52
  if s.respond_to? :specification_version then
@@ -50,22 +54,25 @@ Gem::Specification.new do |s|
50
54
 
51
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
56
  s.add_development_dependency(%q<activerecord>, ["~> 3.0.4"])
53
- s.add_development_dependency(%q<activesupport>, ["~> 3.0.4"])
54
57
  s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
55
58
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_development_dependency(%q<autotest-standalone>, [">= 0"])
60
+ s.add_development_dependency(%q<autotest-growl>, [">= 0"])
56
61
  s.add_development_dependency(%q<rspec>, [">= 0"])
57
62
  else
58
63
  s.add_dependency(%q<activerecord>, ["~> 3.0.4"])
59
- s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
60
64
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
61
65
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
+ s.add_dependency(%q<autotest-standalone>, [">= 0"])
67
+ s.add_dependency(%q<autotest-growl>, [">= 0"])
62
68
  s.add_dependency(%q<rspec>, [">= 0"])
63
69
  end
64
70
  else
65
71
  s.add_dependency(%q<activerecord>, ["~> 3.0.4"])
66
- s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
67
72
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
68
73
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
74
+ s.add_dependency(%q<autotest-standalone>, [">= 0"])
75
+ s.add_dependency(%q<autotest-growl>, [">= 0"])
69
76
  s.add_dependency(%q<rspec>, [">= 0"])
70
77
  end
71
78
  end
@@ -1,5 +1,6 @@
1
1
 
2
2
  module Keytar
3
+ autoload :KeyUtility, "keytar/key_utility"
3
4
  autoload :KeyBuilder, 'keytar/key_builder'
4
5
  def self.included(klass)
5
6
  klass.class_eval {include KeyBuilder}
@@ -1,5 +1,4 @@
1
- require 'active_support/inflector' # used for pluralize
2
- require 'active_support/core_ext/object/blank' # used for blank? and present?
1
+ require File.join(File.dirname(__FILE__), 'key_utility') ## gives us support for Object#blank, Object#present?, String.pluralize without require ActiveSupport
3
2
 
4
3
  module KeyBuilder
5
4
  alias :original_method_missing :method_missing
@@ -31,6 +30,7 @@ module KeyBuilder
31
30
  module Ext
32
31
  # creates class level getter and setter methods for the defaults for config
33
32
  DEFAULTS.keys.each do |key|
33
+ # TODO: re-write without eval
34
34
  eval %{
35
35
  def #{key}(#{key}_input = :key_default)
36
36
  @@#{key} = DEFAULTS[:#{key}] unless defined? @@#{key}
@@ -76,11 +76,12 @@ module KeyBuilder
76
76
 
77
77
  # a way to define configurations for keytar using a hash
78
78
  def key_config(options = {})
79
+ # allow for loose naming of keys configuration symbols can use :key_prefix or just :prefix
79
80
  options.keys.each do |key|
80
81
  options["key_#{key}".to_sym] = options[key] if key.to_s !~ /^key_/
81
82
  end
82
- options.keys.each do |key|
83
- eval("@@#{key} = options[key]") if key.to_s =~ /^key_.*/
83
+ options.each do |key, value|
84
+ self.send( key , value) if self.respond_to? key
84
85
  end
85
86
  end
86
87
  alias :keyfig :key_config
@@ -129,7 +130,8 @@ module KeyBuilder
129
130
  if (options[:key_pluralize_instances] == true ) || (options[:key_pluralize_instances] != false && self.class.key_pluralize_instances.present?)
130
131
  options[:base] = options[:key_plural]||self.class.key_plural||options[:base].pluralize
131
132
  end
132
- options[:unique] = eval("self.#{options[:key_unique]||self.class.key_unique}") unless eval("self.#{options[:key_unique]||self.class.key_unique}") == object_id
133
+ unique = self.send "#{options[:key_unique]||self.class.key_unique}".to_sym
134
+ options[:unique] = unique unless unique == object_id
133
135
  self.class.build_key(options)
134
136
  end
135
137
 
@@ -0,0 +1,26 @@
1
+ # Monkey patches for Object#blank?, Object.present? and String#pluralize
2
+ # If active support is required, this won't be used, but
3
+ # we shouldn't require a ruby project to use ActiveSupport
4
+ # just for these three simple things
5
+
6
+ module KeyUtility
7
+ unless Object.respond_to?(:blank?)
8
+ Object.class_eval do
9
+ def blank?
10
+ respond_to?(:empty?) ? empty? : !self
11
+ end
12
+
13
+ def present?
14
+ !blank?
15
+ end
16
+ end
17
+ end
18
+
19
+ unless String.respond_to? :pluralize
20
+ String.class_eval do
21
+ def pluralize
22
+ self[(self.length - 1), 1] =~ /s/i ? self : "#{self}s"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  class Foo
4
4
  include Keytar
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  ## Gives us ActiveRecord backed model Bar that we can test instances of
4
4
  ActiveRecord::Base.establish_connection(
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.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-05-16 00:00:00 -04:00
18
+ date: 2011-06-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -37,22 +37,6 @@ dependencies:
37
37
  - !ruby/object:Gem::Dependency
38
38
  type: :development
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 15
45
- segments:
46
- - 3
47
- - 0
48
- - 4
49
- version: 3.0.4
50
- name: activesupport
51
- version_requirements: *id002
52
- prerelease: false
53
- - !ruby/object:Gem::Dependency
54
- type: :development
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
40
  none: false
57
41
  requirements:
58
42
  - - ~>
@@ -64,11 +48,11 @@ dependencies:
64
48
  - 7
65
49
  version: 0.8.7
66
50
  name: rake
67
- version_requirements: *id003
51
+ version_requirements: *id002
68
52
  prerelease: false
69
53
  - !ruby/object:Gem::Dependency
70
54
  type: :development
71
- requirement: &id004 !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
72
56
  none: false
73
57
  requirements:
74
58
  - - ~>
@@ -80,6 +64,20 @@ dependencies:
80
64
  - 2
81
65
  version: 1.5.2
82
66
  name: jeweler
67
+ version_requirements: *id003
68
+ prerelease: false
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ name: autotest-standalone
83
81
  version_requirements: *id004
84
82
  prerelease: false
85
83
  - !ruby/object:Gem::Dependency
@@ -93,9 +91,23 @@ dependencies:
93
91
  segments:
94
92
  - 0
95
93
  version: "0"
96
- name: rspec
94
+ name: autotest-growl
97
95
  version_requirements: *id005
98
96
  prerelease: false
97
+ - !ruby/object:Gem::Dependency
98
+ type: :development
99
+ requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ name: rspec
109
+ version_requirements: *id006
110
+ prerelease: false
99
111
  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 "
100
112
  email: richard.schneeman@gmail.com
101
113
  executables: []
@@ -105,19 +117,23 @@ extensions: []
105
117
  extra_rdoc_files:
106
118
  - README.md
107
119
  files:
120
+ - .autotest
121
+ - .rspec
108
122
  - .rvmrc
109
123
  - Gemfile
110
124
  - README.md
111
125
  - Rakefile
112
126
  - VERSION
127
+ - autotest/discover.rb
113
128
  - keytar.gemspec
114
129
  - lib/.DS_Store
115
130
  - lib/keytar.rb
116
131
  - lib/keytar/key_builder.rb
132
+ - lib/keytar/key_utility.rb
117
133
  - license.txt
118
134
  - spec/keytar/key_builder_spec.rb
119
135
  - spec/keytar/keytar_spec.rb
120
- - spec/keytar/spec_helper.rb
136
+ - spec/spec_helper.rb
121
137
  has_rdoc: true
122
138
  homepage: http://github.com/Schnems/keytar
123
139
  licenses:
@@ -155,4 +171,4 @@ summary: A crazy simple library for building keys (in _key_ value store, not ho
155
171
  test_files:
156
172
  - spec/keytar/key_builder_spec.rb
157
173
  - spec/keytar/keytar_spec.rb
158
- - spec/keytar/spec_helper.rb
174
+ - spec/spec_helper.rb