mongoid_dynamic_finder 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,30 @@
1
1
  module Mongoid
2
2
  module Finders
3
3
 
4
- def method_missing(method_id, *arguments, &block)
4
+ def method_missing(method_id, *args, &block)
5
5
  conditions = {}
6
+ bang = false
7
+
6
8
  case method_id.to_s
7
- when /^find_(all|last||first)_?by_([_a-zA-Z]\w*)$/
8
- finder_type = !$1.blank? ? $1.to_sym : :all
9
- $2.split(/_and_/).each_with_index do |attr, i|
10
- conditions[attr] = arguments[i]
11
- end
12
- find(finder_type, :conditions => conditions)
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
- super
22
+ return result
23
+ end
24
+ else
25
+ super
15
26
  end
16
- end
27
+ end
28
+
17
29
  end
18
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module MongoidDynamicFinder
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  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.2
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-21 00:00:00.000000000Z
12
+ date: 2011-11-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &2152463140 !ruby/object:Gem::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: *2152463140
24
+ version_requirements: *2156104680
25
25
  description: making the method find_by_XXX("Mitesh")
26
26
  email:
27
27
  - mitijain123@gmail.com