legacy 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/legacy.gemspec +1 -1
- data/lib/legacy.rb +14 -7
- data/test/legacy_test.rb +11 -0
- metadata +3 -3
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/legacy.gemspec
CHANGED
data/lib/legacy.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
module Legacy
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.real_method(columns, method)
|
7
|
+
columns.inject(method.to_s){|m, c| m.gsub(c.downcase, c)}.to_sym
|
8
|
+
end
|
9
|
+
|
2
10
|
def method_missing(method_id, *args, &block)
|
3
|
-
super(
|
11
|
+
super(Legacy.real_method(attributes.keys, method_id), *args, &block)
|
4
12
|
end
|
5
13
|
|
6
|
-
|
7
|
-
|
8
|
-
|
14
|
+
module ClassMethods
|
15
|
+
def method_missing(method_id, *args, &block)
|
16
|
+
method_id = Legacy.real_method(column_names, method_id) if method_id.to_s =~ /^find(.*)by(.*?)/
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
method_id
|
18
|
+
super(method_id, *args, &block)
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
data/test/legacy_test.rb
CHANGED
@@ -14,4 +14,15 @@ class LegacyTest < ActiveSupport::TestCase
|
|
14
14
|
assert_equal "Testing title", post.title
|
15
15
|
assert_equal "Testing description", post.description
|
16
16
|
end
|
17
|
+
|
18
|
+
test "should find post by find_by_title_and_description" do
|
19
|
+
post = Post.new
|
20
|
+
post.title = "find_title"
|
21
|
+
post.description = "find_description"
|
22
|
+
post.save
|
23
|
+
|
24
|
+
find_post = Post.find_by_title_and_description("find_title", "find_description")
|
25
|
+
assert_equal "find_title", find_post.title
|
26
|
+
assert_equal "find_description", find_post.description
|
27
|
+
end
|
17
28
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: legacy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roy van der Meij
|