Skip to content

Commit

Permalink
Merge pull request #2 from jimii/update_to_grape_1_1
Browse files Browse the repository at this point in the history
feat: update gem to handle new grape version
  • Loading branch information
matfiz authored Dec 23, 2020
2 parents ae4677c + 2a85f75 commit dfd3556
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
49 changes: 28 additions & 21 deletions lib/grape/order.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
require "grape"
require "grape/order/version"
require 'grape'
require 'grape/order/version'

module Grape
module Order
def self.included(base)
base.class_eval do
helpers do
def order(collection)
sorters = params[:order].split(',').map do |s|
if s[0] == '-'
"#{s[1..-1]} asc"
else
"#{s} desc"
end
end
collection.order(sorters.join(','))
module Order # :nodoc:
extend ActiveSupport::Concern

included do
helpers HelperMethods
end

module HelperMethods # :nodoc:
extend Grape::API::Helpers

def order(collection)
sorters = params[:order].split(',').map do |s|
if s[0] == '-'
"#{s[1..-1]} asc"
else
"#{s} desc"
end
end
collection.order(sorters.join(','))
end
end

def self.order(sorter = nil)
params do
optional :order, type: String, default: (sorter if sorter.present?),
desc: 'Set sorting order.'
end
module DSLMethods # :nodoc:
def order(sorter = nil)
params do
optional :order, type: String, default: (sorter if sorter.present?),
desc: 'Set sorting order.'
end
end
end
Grape::API.const_defined?(:Instance) ? Grape::API::Instance.extend(DSLMethods) : Grape::API.extend(DSLMethods)
end
end
end
2 changes: 1 addition & 1 deletion lib/grape/order/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Grape
module Order
VERSION = "0.1.1"
VERSION = "0.1.2".freeze
end
end

0 comments on commit dfd3556

Please sign in to comment.