grape-order 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 947b09b0ddadd7e4f366c2d61369158bab3164d5
4
- data.tar.gz: cd69fd5e22df01dcec572e6fc260bcfb1648caee
2
+ SHA256:
3
+ metadata.gz: 4302de32bb2dbc9600c2c42c31165b5f442ba05add622bb79f98d296fad50824
4
+ data.tar.gz: e2074e44f9126df0b99cb0bb57e54ce5568c9b320e2358875f4cd8ebfa49cbe7
5
5
  SHA512:
6
- metadata.gz: 4a0467d1a952f6cf1c0f814ca23e7aa816d48ef0d8afc41c25b88aadd79a7fef499b1287f08d8c090e3f20dfb25272cd52723bc39b880b7ef7308d4dc6ad638d
7
- data.tar.gz: 6dc86fe32eb1bbd33bbc4431457f22a1be41dd319da1dbdad0ee52be17b20ebaae7b6491d3420e17f879d3d499fc7d2713c0c1a8750125975e30608195f8f5c0
6
+ metadata.gz: 1b7d5252dc4d8f68465d9b6ce7621372da10d6c38235251ce4c089985c9404f6ef0694e2a070977bb720ba9920eba2103daa28f23db785cbd11de723867183e5
7
+ data.tar.gz: ed0c5b8b3f978765705fe5fd92be2c53c6dd03634627ed0eaa3ef9e5c5113b49f41d8b5f7570a00e8b85e14909a5a2ee31cc392e3aaf9f6cc144c499d68b2b9b
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .idea
2
2
  Gemfile.lock
3
- *.gem
3
+ *.gem
4
+ coverage
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Grape::Order [![Gem Version](https://badge.fury.io/rb/grape-order.png)]
1
+ # Grape::Order [![Gem Version](https://badge.fury.io/rb/grape-order.png)][![Code Climate](https://codeclimate.com/github/PrositAS/grape-order/badges/gpa.svg)](https://codeclimate.com/github/PrositAS/grape-order)[![Build Status](https://semaphoreci.com/api/v1/prositas/grape-order/branches/master/badge.svg)](https://semaphoreci.com/prositas/grape-order)
2
2
 
3
3
  Collection ordering for [grape](https://github.com/intridea/grape) API framework.
4
4
 
@@ -27,12 +27,12 @@ $ gem install grape-order
27
27
  ```ruby
28
28
  class MyApi < Grape::API
29
29
  # Include Grape::Sort module in your api
30
- include Grape::Sort
30
+ include Grape::Order
31
31
 
32
32
  resource :comments do
33
33
  desc 'Return a list of comments.'
34
34
 
35
- # Annotate action with `paginate`.
35
+ # Annotate action with `order`.
36
36
  # This will add an optional param: order
37
37
  #
38
38
  # You can optionally set the default :order setting to the fields of your choice.
@@ -54,6 +54,7 @@ Now you can pass a string `order` param to HTTP request to your endpoint structu
54
54
 
55
55
  - prepend field name by `-` to get ascending order, like `-created_at`
56
56
  - pass multiple fields to order by separating them by comma, like `-created_at, name`
57
+ - ordering on nested resources is also supported, eg: 'posts.created_at, -comments.created_at'
57
58
 
58
59
  ```
59
60
  curl -v http://lvh.me:3000/comments?order=-created_at
@@ -64,4 +65,4 @@ curl -v http://lvh.me:3000/comments?order=-created_at
64
65
  The gem structure was based on https://github.com/monterail/grape-kaminari
65
66
  (which can be used for pagination).
66
67
 
67
- Feel free to submit issue with bug report or pull requests on GitHub at https://github.com/PrositAS/grape-order.
68
+ Feel free to submit issue with bug report or pull requests on GitHub at https://github.com/PrositAS/grape-order.
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "simplecov"
28
29
  spec.add_development_dependency "rack-test"
29
30
  spec.add_development_dependency "rspec", "~> 2.9"
30
31
  end
@@ -1,30 +1,37 @@
1
- require "grape"
2
- require "grape/order/version"
1
+ require 'grape'
2
+ require 'grape/order/version'
3
3
 
4
4
  module Grape
5
- module Order
6
- def self.included(base)
7
- base.class_eval do
8
- helpers do
9
- def order(collection)
10
- sorters = params[:order].split(',').map do |s|
11
- if s[0] == '-'
12
- "#{s[1..-1]} asc"
13
- else
14
- "#{s} desc"
15
- end
16
- end
17
- collection.order(sorters.join(','))
5
+ module Order # :nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ helpers HelperMethods
10
+ end
11
+
12
+ module HelperMethods # :nodoc:
13
+ extend Grape::API::Helpers
14
+
15
+ def order(collection)
16
+ sorters = params[:order].split(',').map do |s|
17
+ if s[0] == '-'
18
+ "#{s[1..-1]} asc"
19
+ else
20
+ "#{s} desc"
18
21
  end
19
22
  end
23
+ collection.order(sorters.join(','))
24
+ end
25
+ end
20
26
 
21
- def self.order(sorter = nil)
22
- params do
23
- optional :order, type: String, default: (sorter if sorter.present?),
24
- desc: 'Set sorting order.'
25
- end
27
+ module DSLMethods # :nodoc:
28
+ def order(sorter = nil)
29
+ params do
30
+ optional :order, type: String, default: (sorter if sorter.present?),
31
+ desc: 'Set sorting order.'
26
32
  end
27
33
  end
28
34
  end
35
+ Grape::API.const_defined?(:Instance) ? Grape::API::Instance.extend(DSLMethods) : Grape::API.extend(DSLMethods)
29
36
  end
30
- end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Order
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2".freeze
4
4
  end
5
5
  end
@@ -1,11 +1,14 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'simplecov'
4
+ SimpleCov.start
3
5
  require 'rspec'
4
6
  require 'grape'
5
7
  require 'grape-order'
6
8
  require 'active_record'
7
9
  require 'rack/test'
8
10
 
11
+
9
12
  # Requires supporting files with custom matchers and macros, etc,
10
13
  # in ./support/ and its subdirectories.
11
14
  Dir['#{File.dirname(__FILE__)}/support/**/*.rb'].each {|f| require f}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-order
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grzegorz Brzezinka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rack-test
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -146,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
160
  - !ruby/object:Gem::Version
147
161
  version: '0'
148
162
  requirements: []
149
- rubyforge_project:
150
- rubygems_version: 2.5.1
163
+ rubygems_version: 3.0.3
151
164
  signing_key:
152
165
  specification_version: 4
153
166
  summary: collection ordering for grape