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.
@@ -1,3 +1,8 @@
1
+ == 0.2.0 2007-10-09
2
+
3
+ * Support for to_multi_part_class_name => MultiPartClassName
4
+ * String#to_xxx support
5
+
1
6
  == 0.1.1 2007-06-17
2
7
 
3
8
  * Added tests (using mocha)
@@ -4,7 +4,6 @@ Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
6
  lib/to_activerecord.rb
7
- lib/to_activerecord/fixnum.rb
8
7
  lib/to_activerecord/version.rb
9
8
  scripts/txt2html
10
9
  setup.rb
@@ -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].capitalize.constantize rescue nil
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
@@ -1,8 +1,8 @@
1
1
  module ToActiverecord #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  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
@@ -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.1.1</a>
36
+ <a href="http://rubyforge.org/projects/to_activerecord" class="numbers">0.2.0</a>
37
37
  </div>
38
38
  <h1>&#x2192; 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>, 16th June 2007<br>
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.1
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.1.1
7
- date: 2007-06-17 00:00:00 +02:00
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
@@ -1,15 +0,0 @@
1
- module ToActiveRecord
2
- module Fixnum
3
- module ClassMethods
4
-
5
- end
6
-
7
- extend ClassMethods
8
-
9
- def self.included(receiver)
10
- receiver.extend(ClassMethods)
11
- end
12
-
13
-
14
- end
15
- end