Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
ta_ransack_mongo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
ta_ransack_mongo
Commits
0ec5b7ac
Commit
0ec5b7ac
authored
Nov 24, 2014
by
Bruno Buccolo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds #start and #mstart matchers
parent
c5847b7f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
1 deletion
+45
-1
README.md
README.md
+2
-0
mongo_adapter.rb
lib/ransack_mongo/mongo_adapter.rb
+15
-1
mongo_adapter_spec.rb
spec/ransack_mongo/mongo_adapter_spec.rb
+28
-0
No files found.
README.md
View file @
0ec5b7ac
...
@@ -56,6 +56,8 @@ end
...
@@ -56,6 +56,8 @@ end
*
not_eq
*
not_eq
*
cont
*
cont
*
in
*
in
*
start
*
mstart
*
gt
*
gt
*
lt
*
lt
*
gteq
*
gteq
...
...
lib/ransack_mongo/mongo_adapter.rb
View file @
0ec5b7ac
module
RansackMongo
module
RansackMongo
class
MongoAdapter
class
MongoAdapter
PREDICATES
=
%w[eq not_eq cont in gt lt gteq lteq]
PREDICATES
=
%w[eq not_eq cont in
start mstart
gt lt gteq lteq]
def
initialize
def
initialize
@query
=
{}
@query
=
{}
...
@@ -26,6 +26,20 @@ module RansackMongo
...
@@ -26,6 +26,20 @@ module RansackMongo
@query
[
attr
]
=
{
'$in'
=>
value
}
@query
[
attr
]
=
{
'$in'
=>
value
}
end
end
def
start_matcher
(
attr
,
value
)
@query
[
attr
]
=
{
'$in'
=>
[
/^
#{
value
}
/
]
}
end
def
mstart_matcher
(
attr
,
value
)
values
=
value
.
split
(
","
).
map
do
|
current
|
if
(
current
=
current
.
strip
).
length
>
0
/^
#{
current
}
/
end
end
.
compact
@query
[
attr
]
=
{
'$in'
=>
values
}
end
def
gt_matcher
(
attr
,
value
)
def
gt_matcher
(
attr
,
value
)
append_sizeable_matcher
(
'$gt'
,
attr
,
value
)
append_sizeable_matcher
(
'$gt'
,
attr
,
value
)
end
end
...
...
spec/ransack_mongo/mongo_adapter_spec.rb
View file @
0ec5b7ac
...
@@ -34,6 +34,34 @@ module RansackMongo
...
@@ -34,6 +34,34 @@ module RansackMongo
end
end
end
end
describe
'#start'
do
it
'returns the matcher'
do
subject
.
start_matcher
(
'object_ref'
,
'Bruno'
)
expect
(
subject
.
to_query
).
to
eq
(
"object_ref"
=>
{
"$in"
=>
[
/^Bruno/
]
})
end
end
describe
'#mstart'
do
it
'returns the matcher'
do
subject
.
mstart_matcher
(
'name'
,
'Pablo, Bruno,Dude'
)
expect
(
subject
.
to_query
).
to
eq
(
"name"
=>
{
"$in"
=>
[
/^Pablo/
,
/^Bruno/
,
/^Dude/
]
})
end
it
'cleans up the input'
do
subject
.
mstart_matcher
(
'name'
,
',, , ,Pablo,,,, ,, , , ,'
)
expect
(
subject
.
to_query
).
to
eq
(
"name"
=>
{
"$in"
=>
[
/^Pablo/
]
})
end
it
'accepts single values'
do
subject
.
mstart_matcher
(
'name'
,
'Pablo'
)
expect
(
subject
.
to_query
).
to
eq
(
"name"
=>
{
"$in"
=>
[
/^Pablo/
]
})
end
end
context
'when combine gt lt gteq and lteq'
do
context
'when combine gt lt gteq and lteq'
do
it
'returns all matchers'
do
it
'returns all matchers'
do
subject
.
gt_matcher
(
'count'
,
'1'
)
subject
.
gt_matcher
(
'count'
,
'1'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment