acts_as_keyed 0.0.5 → 0.0.6

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 ADDED
@@ -0,0 +1,31 @@
1
+ # ActsAsKeyed
2
+
3
+ A simple plugin that automatically generates a key for a model on create. It takes care of protecting the key, automatically generating it and making sure it is unique.
4
+
5
+ The key is based on Tantek's NewBase60 schema to make human readable keys, but you can change the chars used by passing in an option to the acts_as_keyed method.
6
+
7
+ http://tantek.pbworks.com/w/page/19402946/NewBase60
8
+
9
+ ## Options
10
+
11
+ * **as_params** [*False*] If true, this will be used as the id of the object when creating URLs and you will be able to Object.find(key)
12
+ * **size** - [_10_] The number of characters to make the key
13
+ * **chars** - [_NewBase60_] An array of Chars to use when generating the key
14
+
15
+ ## Example
16
+
17
+ create_table "projects" do |t|
18
+ t.string "key"
19
+ end
20
+
21
+ class Project < ActiveRecord::Base
22
+ acts_as_keyed :as_params => true
23
+ end
24
+
25
+ Project.create
26
+ Project.first.key
27
+ => '8xsk38s92p'
28
+
29
+ Project.find('8xsk38s92') == Project.find(1)
30
+
31
+ Copyright (c) 2011 Jeremy Hubert, released under the MIT license
@@ -1,3 +1,3 @@
1
1
  module ActsAsKeyed
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/acts_as_keyed.rb CHANGED
@@ -12,7 +12,11 @@ module ActsAsKeyed
12
12
 
13
13
  raise ArgumentError, "#{self.name} is missing key column" if columns_hash['key'].nil?
14
14
 
15
- before_validation_on_create :create_key
15
+ if Rails.version < '3'
16
+ before_validation_on_create :create_key
17
+ else
18
+ before_validation :create_key, :on => :create
19
+ end
16
20
 
17
21
  attr_protected :key
18
22
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_keyed
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Hubert
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-07 00:00:00 -08:00
18
+ date: 2011-03-08 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -31,6 +31,7 @@ extra_rdoc_files: []
31
31
  files:
32
32
  - .gitignore
33
33
  - Gemfile
34
+ - README.md
34
35
  - Rakefile
35
36
  - acts_as_keyed.gemspec
36
37
  - lib/acts_as_keyed.rb