mongoid_dynamic_finder 0.0.2 → 0.0.3
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.
@@ -1,18 +1,30 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Finders
|
3
3
|
|
4
|
-
|
4
|
+
def method_missing(method_id, *args, &block)
|
5
5
|
conditions = {}
|
6
|
+
bang = false
|
7
|
+
|
6
8
|
case method_id.to_s
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
when /^find_(all|last||first)_?by_([_a-zA-Z]\w*)(!?)$/
|
10
|
+
finder_type = $1.blank? ? :first : $1.to_sym
|
11
|
+
bang = true if $3 == '!'
|
12
|
+
|
13
|
+
$2.split(/_and_/).each_with_index do |attr, i|
|
14
|
+
conditions[attr] = args[i]
|
15
|
+
end
|
16
|
+
|
17
|
+
result = find(finder_type, :conditions => conditions)
|
18
|
+
|
19
|
+
if result.nil? and bang
|
20
|
+
raise Mongoid::Errors::DocumentNotFound.new(self.class, args)
|
13
21
|
else
|
14
|
-
|
22
|
+
return result
|
23
|
+
end
|
24
|
+
else
|
25
|
+
super
|
15
26
|
end
|
16
|
-
end
|
27
|
+
end
|
28
|
+
|
17
29
|
end
|
18
|
-
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_dynamic_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-22 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156104680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156104680
|
25
25
|
description: making the method find_by_XXX("Mitesh")
|
26
26
|
email:
|
27
27
|
- mitijain123@gmail.com
|