to_activerecord 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +0 -1
- data/lib/to_activerecord.rb +12 -3
- data/lib/to_activerecord/version.rb +2 -2
- data/test/test_to_activerecord.rb +13 -0
- data/website/index.html +2 -2
- metadata +3 -4
- data/lib/to_activerecord/fixnum.rb +0 -15
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/lib/to_activerecord.rb
CHANGED
@@ -10,16 +10,25 @@ rescue LoadError
|
|
10
10
|
require 'active_support'
|
11
11
|
end
|
12
12
|
|
13
|
-
# Fixnum.send(:include, ToActiverecord::Fixnum)
|
14
|
-
|
15
13
|
class Fixnum
|
16
14
|
def method_missing(meth, *args, &block)
|
17
15
|
pattern = /^to_([a-z][a-z_]*)$/
|
18
16
|
if match = pattern.match(meth.to_s)
|
19
|
-
if match_class = match[1].
|
17
|
+
if match_class = match[1].camelize.constantize rescue nil
|
20
18
|
return match_class.send(:find, *([self] + args), &block)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
super
|
24
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class String
|
26
|
+
def method_missing(meth, *args, &block)
|
27
|
+
pattern = /^to_([a-z][a-z_]*)$/
|
28
|
+
if match = pattern.match(meth.to_s)
|
29
|
+
result = self.to_i.send(meth, *args, &block) rescue nil
|
30
|
+
return result if result
|
31
|
+
end
|
32
|
+
super
|
33
|
+
end
|
25
34
|
end
|
@@ -9,6 +9,9 @@ class Post
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
class MultiPartClassName
|
13
|
+
end
|
14
|
+
|
12
15
|
class TestToActiverecord < Test::Unit::TestCase
|
13
16
|
|
14
17
|
def setup
|
@@ -23,6 +26,10 @@ class TestToActiverecord < Test::Unit::TestCase
|
|
23
26
|
assert_equal(post, 60.to_post, "to_activerecord not working")
|
24
27
|
end
|
25
28
|
|
29
|
+
def test_to_multi_part_class_name
|
30
|
+
MultiPartClassName.expects(:find).with(100).returns(true)
|
31
|
+
100.to_multi_part_class_name
|
32
|
+
end
|
26
33
|
|
27
34
|
def test_to_unknown_post_id
|
28
35
|
assert_raise(PostError) { 999.to_post }
|
@@ -31,4 +38,10 @@ class TestToActiverecord < Test::Unit::TestCase
|
|
31
38
|
def test_to_unknown_class
|
32
39
|
assert_raise(NoMethodError) { 30.to_foobar }
|
33
40
|
end
|
41
|
+
|
42
|
+
def test_to_s_still_work
|
43
|
+
assert_equal("expected", "expected".to_s)
|
44
|
+
assert_equal("123", 123.to_s)
|
45
|
+
assert_equal("actionlist", [:action, "list"].to_s)
|
46
|
+
end
|
34
47
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>to_activerecord</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/to_activerecord"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/to_activerecord" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/to_activerecord" class="numbers">0.2.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ 7.to_car == Car.find(7)</h1>
|
39
39
|
|
@@ -106,7 +106,7 @@
|
|
106
106
|
|
107
107
|
<p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a>.</p>
|
108
108
|
<p class="coda">
|
109
|
-
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>,
|
109
|
+
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 17th June 2007<br>
|
110
110
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
111
111
|
</p>
|
112
112
|
</div>
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4.
|
2
|
+
rubygems_version: 0.9.4.3
|
3
3
|
specification_version: 1
|
4
4
|
name: to_activerecord
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-10-09 00:00:00 +10:00
|
8
8
|
summary: "Find ActiveRecord instances via their ID value. Now you can use 37.to_post instead of Post.find(37). Used in conjunction with the map_by_method gem: [37,103].map_by_to_post"
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- README.txt
|
36
36
|
- Rakefile
|
37
37
|
- lib/to_activerecord.rb
|
38
|
-
- lib/to_activerecord/fixnum.rb
|
39
38
|
- lib/to_activerecord/version.rb
|
40
39
|
- scripts/txt2html
|
41
40
|
- setup.rb
|