From aeb69e4abf69993157f9970fa5503b7f9fd4aab5 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 20 Dec 2012 15:13:26 -0800 Subject: Define ascending method in CouchRest::Model::Designs::View so we can call the order either way. --- core/lib/extensions/couchrest.rb | 8 ++++++++ core/lib/leap_web_core.rb | 1 + help/app/models/ticket_selection.rb | 10 +++------- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 core/lib/extensions/couchrest.rb diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb new file mode 100644 index 0000000..a8da23b --- /dev/null +++ b/core/lib/extensions/couchrest.rb @@ -0,0 +1,8 @@ +class CouchRest::Model::Designs::View + + # so we can called Ticket.method.descending or Ticket.method.ascending + def ascending + self + end + +end diff --git a/core/lib/leap_web_core.rb b/core/lib/leap_web_core.rb index 8826880..a58d140 100644 --- a/core/lib/leap_web_core.rb +++ b/core/lib/leap_web_core.rb @@ -7,6 +7,7 @@ require "couchrest_session_store" require "json" require "extensions/testing" +require "extensions/couchrest" require "leap_web_core/engine" module LeapWebCore diff --git a/help/app/models/ticket_selection.rb b/help/app/models/ticket_selection.rb index cb20f5b..bebe5fc 100644 --- a/help/app/models/ticket_selection.rb +++ b/help/app/models/ticket_selection.rb @@ -8,12 +8,7 @@ class TicketSelection end def tickets - #TODO: can this be more succinct? - if order - Ticket.send(finder_method).startkey(startkey).endkey(endkey).send(order) - else - Ticket.send(finder_method).startkey(startkey).endkey(endkey) - end + Ticket.send(finder_method).startkey(startkey).endkey(endkey).send(order) end protected @@ -47,7 +42,8 @@ class TicketSelection end def order - 'descending' if @options[:sort_order].end_with? 'desc' + # we have defined the ascending method to return the view itself: + (@options[:sort_order].end_with? 'desc') ? 'descending' : 'ascending' end -- cgit v1.2.3