[Jifty-commit] jifty branch, master, updated. 29e12eb04d7dd18952a540e17477b3cc882db81a
Jifty commits
jifty-commit at lists.jifty.org
Thu Mar 18 07:16:08 EDT 2010
The branch, master has been updated
via 29e12eb04d7dd18952a540e17477b3cc882db81a (commit)
from 2d4a432a543bfc64d9b0333d4d0758e6bf6da663 (commit)
Summary of changes:
lib/Jifty/Plugin/REST.pm | 2 +-
lib/Jifty/Plugin/REST/Dispatcher.pm | 44 +++++++++++++++++++++++++------
t/TestApp-Plugin-REST/t/02-basic-use.t | 6 +++-
3 files changed, 41 insertions(+), 11 deletions(-)
- Log -----------------------------------------------------------------
commit 29e12eb04d7dd18952a540e17477b3cc882db81a
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Thu Mar 18 07:08:36 2010 -0400
Implement __not/<column>/<value> for /=/search
diff --git a/lib/Jifty/Plugin/REST.pm b/lib/Jifty/Plugin/REST.pm
index 24e0581..1bdeaeb 100644
--- a/lib/Jifty/Plugin/REST.pm
+++ b/lib/Jifty/Plugin/REST.pm
@@ -4,7 +4,7 @@ use warnings;
package Jifty::Plugin::REST;
use base qw/Jifty::Plugin/;
-our $VERSION = '1.12';
+our $VERSION = '1.13';
=head1 NAME
diff --git a/lib/Jifty/Plugin/REST/Dispatcher.pm b/lib/Jifty/Plugin/REST/Dispatcher.pm
index 5c490cf..95f855d 100644
--- a/lib/Jifty/Plugin/REST/Dispatcher.pm
+++ b/lib/Jifty/Plugin/REST/Dispatcher.pm
@@ -140,8 +140,18 @@ looking for Tasks with due dates 1999-12-25 OR 2000-12-25, you can use:
/=/search/Task/due/1999-12-25/due/2000-12-25/
-There are also some pseudo-columns that affect the results, but are not columns
-that are searched:
+
+There are also some pseudo-columns. They are prefixed by __ to avoid collisions
+with actual column names.
+
+Not:
+
+ .../__not/<column>/<value>
+
+This lets you search for records whose value for the column is NOT equal
+to the specified value.
+
+Ordering:
.../__order_by/<column>
.../__order_by_asc/<column>
@@ -150,6 +160,8 @@ that are searched:
These let you change the output order of the results. Multiple '__order_by's
will be respected.
+Pagination:
+
.../__page/<number>
.../__per_page/<number>
@@ -646,12 +658,6 @@ sub search_items {
my @pieces = grep {length} split '/', $fragment;
my $ret = ['search', $model, @pieces];
- # if they provided an odd number of pieces, the last is the output column
- my $field;
- if (@pieces % 2 == 1) {
- $field = pop @pieces;
- }
-
# limit to the key => value pairs they gave us
my $collection = eval { $model->collection_class->new }
or abort(404);
@@ -703,6 +709,20 @@ sub search_items {
);
}
},
+ __not => sub {
+ my $column = shift;
+ my $value = shift @pieces;
+
+ my $canonicalizer = "canonicalize_$column";
+ $value = $record->$canonicalizer($value)
+ if $record->can($canonicalizer);
+
+ $collection->limit(
+ column => $column,
+ value => $value,
+ operator => '!=',
+ );
+ },
);
# this was called __limit before it was generalized
@@ -715,7 +735,7 @@ sub search_items {
$special{__order_by_asc} = $special{__order_by};
$special{__order_by_desc} = sub { $special{__order_by}->($_[0], 'DESC') };
- while (@pieces) {
+ while (@pieces > 1) {
my $column = shift @pieces;
my $value = shift @pieces;
@@ -731,6 +751,12 @@ sub search_items {
}
}
+ # if they provided an odd number of pieces, the last is the output column
+ my $field;
+ if (@pieces) {
+ $field = shift @pieces;
+ }
+
if (defined($per_page) || defined($current_page)) {
$per_page = 15 unless defined $per_page;
$current_page = 1 unless defined $current_page;
diff --git a/t/TestApp-Plugin-REST/t/02-basic-use.t b/t/TestApp-Plugin-REST/t/02-basic-use.t
index 5ac2e0e..3314508 100644
--- a/t/TestApp-Plugin-REST/t/02-basic-use.t
+++ b/t/TestApp-Plugin-REST/t/02-basic-use.t
@@ -9,7 +9,7 @@ This is a template for your own tests. Copy it and modify it.
=cut
-use Jifty::Test::Dist tests => 78;
+use Jifty::Test::Dist tests => 80;
use Jifty::Test::WWW::Mechanize;
my $server = Jifty::Test->make_server;
@@ -89,6 +89,10 @@ $mech->get_ok('/=/search/user/id/1.yml');
my $content = get_content();
is_deeply($content, [{ name => 'test', email => 'test at example.com', id => 1, tasty => undef }]);
+$mech->get_ok('/=/search/user/__not/id/1.yml');
+$content = get_content();
+is_deeply($content, [{ name => 'moose', email => 'moose at example.com', id => 2, tasty => undef }]);
+
$mech->get_ok('/=/search/user/id/1/name/test.yml');
$content = get_content();
is_deeply($content, [{ name => 'test', email => 'test at example.com', id => 1, tasty => undef }]);
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list