-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jimii/update_to_grape_1_1
feat: update gem to handle new grape version
- Loading branch information
Showing
2 changed files
with
29 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |