mongoid_query_string_interface 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,7 +8,7 @@ model.
8
8
 
9
9
  == Repository
10
10
 
11
- http://github.com/vicentemundim/mongoid-query-string-interface
11
+ http://github.com/vicentemundim/mongoid_query_string_interface
12
12
 
13
13
  = Installing
14
14
 
@@ -25,22 +25,22 @@ Or, if you are using rails, put this in your Gemfile:
25
25
  To use it, just extend Mongoid::QueryStringInterface in your document model:
26
26
 
27
27
  class Document
28
- include Mongoid::Document
29
- extend Mongoid::QueryInterfaceString
30
-
31
- # ... add fields here
32
- end
28
+ include Mongoid::Document
29
+ extend Mongoid::QueryInterfaceString
30
+
31
+ # ... add fields here
32
+ end
33
33
 
34
34
  Then, in your controllers put:
35
35
 
36
36
  def index
37
- @documents = Document.filter_by(params)
38
- # ... do something like render a HTML template or a XML/JSON view of documents
39
- end
37
+ @documents = Document.filter_by(params)
38
+ # ... do something like render a HTML template or a XML/JSON view of documents
39
+ end
40
40
 
41
41
  That's it! Now you can do something like this:
42
42
 
43
- http://myhost.com/documents?tags.all=ruby|rails|mongodb&tags.nin=sql|java&updated_at.gt=2010-01-01&created_at.desc&per_page=10&page=3
43
+ http://myhost.com/documents?tags.all=ruby|rails|mongodb&tags.nin=sql|java&updated_at.gt=2010-01-01&created_at.desc&per_page=10&page=3
44
44
 
45
45
  This would get all documents which have the tags 'ruby', 'rails' and 'mongo',
46
46
  and that don't have both 'sql' and 'java' tags, and that were updated after
@@ -50,7 +50,7 @@ page, and the 3rd page of results.
50
50
  You could even query for embedded documents, and use any of the Mongodb
51
51
  conditional operators:
52
52
 
53
- http://myhost.com/documents?comments.author=Shrek
53
+ http://myhost.com/documents?comments.author=Shrek
54
54
 
55
55
  Which would get all documents that have been commented by 'Shrek'. Basically,
56
56
  any valid path that you can use in a Mongoid::Criteria can be used here, and
@@ -87,7 +87,7 @@ module Mongoid
87
87
  end
88
88
 
89
89
  def parse_value(value, operator)
90
- parse_date(value) or parse_integer(value) or parse_array(value, operator) or value
90
+ parse_date(value) or parse_integer(value) or parse_array(value, operator) or parse_regex(value) or value
91
91
  end
92
92
 
93
93
  def parse_date(date)
@@ -111,6 +111,12 @@ module Mongoid
111
111
  def parse_array(value, operator)
112
112
  split_and_strip(value) if array_operator?(operator)
113
113
  end
114
+
115
+ def parse_regex(regex)
116
+ if match = regex.match(/^\/(.*)\/(i|m|x)?$/)
117
+ eval(match[0])
118
+ end
119
+ end
114
120
 
115
121
  def array_operator?(operator)
116
122
  ARRAY_CONDITIONAL_OPERATORS.map { |op| "$#{op}" }.include?(operator.to_s)
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
3
  module QueryStringInterface #:nodoc
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_query_string_interface
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Vicente Mundim