acts_as_keyed 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +47 -0
- data/Gemfile.lock +38 -0
- data/README.md +1 -0
- data/lib/acts_as_keyed/class_methods.rb +9 -1
- data/lib/acts_as_keyed/instance_methods.rb +1 -7
- data/lib/acts_as_keyed/version.rb +1 -1
- metadata +6 -4
data/.rvmrc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.8.7-p352@clean"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
|
14
|
+
#
|
15
|
+
# First we attempt to load the desired environment directly from the environment
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
17
|
+
# CLI and selector. If you want feedback on which environment was used then
|
18
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
+
#
|
20
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
23
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
+
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
29
|
+
else
|
30
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
+
if ! rvm --create "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
fi
|
37
|
+
|
38
|
+
#
|
39
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
+
# necessary.
|
42
|
+
#
|
43
|
+
# filename=".gems"
|
44
|
+
# if [[ -s "$filename" ]] ; then
|
45
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
46
|
+
# fi
|
47
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
acts_as_keyed (0.0.9)
|
5
|
+
activerecord (~> 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.2.1)
|
11
|
+
activesupport (= 3.2.1)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
activerecord (3.2.1)
|
14
|
+
activemodel (= 3.2.1)
|
15
|
+
activesupport (= 3.2.1)
|
16
|
+
arel (~> 3.0.0)
|
17
|
+
tzinfo (~> 0.3.29)
|
18
|
+
activesupport (3.2.1)
|
19
|
+
i18n (~> 0.6)
|
20
|
+
multi_json (~> 1.0)
|
21
|
+
arel (3.0.0)
|
22
|
+
builder (3.0.0)
|
23
|
+
i18n (0.6.0)
|
24
|
+
multi_json (1.0.4)
|
25
|
+
rake (0.9.2.2)
|
26
|
+
sqlite3 (1.3.5)
|
27
|
+
sqlite3-ruby (1.3.3)
|
28
|
+
sqlite3 (>= 1.3.3)
|
29
|
+
tzinfo (0.3.31)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
activesupport (~> 3.0)
|
36
|
+
acts_as_keyed!
|
37
|
+
rake
|
38
|
+
sqlite3-ruby
|
data/README.md
CHANGED
@@ -11,6 +11,7 @@ http://tantek.pbworks.com/w/page/19402946/NewBase60
|
|
11
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
12
|
* **size** - [_10_] The number of characters to make the key
|
13
13
|
* **chars** - [_NewBase60_] An array of Chars to use when generating the key
|
14
|
+
* **column** - [*key*] The name of the column to store the key. Accepts a symbol or string.
|
14
15
|
|
15
16
|
## Example
|
16
17
|
|
@@ -29,8 +29,16 @@ module ActsAsKeyed
|
|
29
29
|
def key_exists?(k)
|
30
30
|
exists?(["#{options[:column]} = ?", k])
|
31
31
|
end
|
32
|
+
|
33
|
+
def generate_key(size = nil)
|
34
|
+
size ||= options[:size]
|
35
|
+
|
36
|
+
code_array=[]
|
37
|
+
1.upto(options[:size]) { code_array << options[:chars][rand(options[:chars].length)] }
|
38
|
+
code_array.join('')
|
39
|
+
end
|
32
40
|
end
|
33
|
-
|
41
|
+
|
34
42
|
include InstanceMethods
|
35
43
|
end
|
36
44
|
end
|
@@ -23,18 +23,12 @@ module ActsAsKeyed
|
|
23
23
|
def create_key
|
24
24
|
k = nil
|
25
25
|
100.times do
|
26
|
-
k =
|
26
|
+
k = self.class.generate_key
|
27
27
|
break if !self.class.key_exists?(k)
|
28
28
|
k = nil
|
29
29
|
end
|
30
30
|
raise NoAvailableKeysError if k.nil?
|
31
31
|
self.key = k
|
32
32
|
end
|
33
|
-
|
34
|
-
def random_key
|
35
|
-
code_array=[]
|
36
|
-
1.upto(options[:size]) { code_array << options[:chars][rand(options[:chars].length)] }
|
37
|
-
code_array.join('')
|
38
|
-
end
|
39
33
|
end
|
40
34
|
end
|
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
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: 2012-
|
18
|
+
date: 2012-04-30 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -44,7 +44,9 @@ extra_rdoc_files: []
|
|
44
44
|
files:
|
45
45
|
- .gemtest
|
46
46
|
- .gitignore
|
47
|
+
- .rvmrc
|
47
48
|
- Gemfile
|
49
|
+
- Gemfile.lock
|
48
50
|
- LICENSE
|
49
51
|
- README.md
|
50
52
|
- Rakefile
|