senro 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -2
- data/README.md +14 -6
- data/lib/senro/query_params_formatter.rb +23 -0
- data/lib/senro/version.rb +3 -1
- data/lib/senro.rb +1 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 696fbf72ba815d79a7698e65507dc96be100474f9c9c7206500784b054c4b224
|
4
|
+
data.tar.gz: 5f93be5e568bde5cd1ab13c60995721715deefc7c3d77350ba8085102e112b18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35603e85cab36bd5db1b9fd9f73f766922f2927ea087a995149e785a4951b8259663daf9acbb30879d6430ea741eea37ea6f71e19045f435da9ad99c39dd4273
|
7
|
+
data.tar.gz: 69741b9903e7e52bdc008d14a266021e1a270a7a8a2ab1f6b0791368e7c0ccdd661ebba313ef5e6e1eb7f11bb52687e4c0815f669e1f8303dad97fb2e921da2f
|
data/.travis.yml
CHANGED
@@ -3,5 +3,16 @@ sudo: false
|
|
3
3
|
language: ruby
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
|
-
- 2.
|
7
|
-
|
6
|
+
- 2.4
|
7
|
+
- 2.5
|
8
|
+
- 2.6
|
9
|
+
|
10
|
+
before_install:
|
11
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
12
|
+
- gem install bundler -v 1.17.2
|
13
|
+
|
14
|
+
before_script:
|
15
|
+
- docker-compose up -d
|
16
|
+
|
17
|
+
after_script:
|
18
|
+
- docker-compose down
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Senro
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
[![Build Status](https://travis-ci.org/walkersumida/senro.svg?branch=master)](https://travis-ci.org/walkersumida/senro)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/senro.svg)](https://badge.fury.io/rb/senro)
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -21,16 +20,25 @@ Or install it yourself as:
|
|
21
20
|
$ gem install senro
|
22
21
|
|
23
22
|
## Usage
|
23
|
+
### QueryParamsFormatter#sorting
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
puts params[:sort]
|
27
|
+
# => '+id,-name'
|
28
|
+
|
29
|
+
order_clause = Senro::QueryParamsFormatter.sorting(params[:sort])
|
24
30
|
|
25
|
-
|
31
|
+
puts order_clause
|
32
|
+
# => 'id ASC, name DESC'
|
33
|
+
|
34
|
+
@items = Item.all.order(order_clause)
|
35
|
+
```
|
26
36
|
|
27
37
|
## Development
|
28
38
|
|
29
39
|
- Run `docker-compose run ruby bundle exec rake spec` to run the tests.
|
30
40
|
- You can also run `docker-compose run ruby bin/console` for an interactive prompt that will allow you to experiment.
|
31
41
|
|
32
|
-
To install this gem onto your local machine, run `bundle install --path vendor/bundle`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
-
|
34
42
|
## Contributing
|
35
43
|
|
36
44
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/senro. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Senro
|
4
|
+
class QueryParamsFormatter
|
5
|
+
# Format RESTful API's query params to SQL order clause.
|
6
|
+
# +: asc
|
7
|
+
# -: desc
|
8
|
+
# none(default): asc
|
9
|
+
#
|
10
|
+
# @param param [String] format string. e.g. `+id,-name`
|
11
|
+
# @return [String] formated stirng
|
12
|
+
def self.sorting(param)
|
13
|
+
attributes = param.split(',')
|
14
|
+
attributes.map do |attr|
|
15
|
+
if /^\-/.match(attr).nil?
|
16
|
+
"#{attr.strip.gsub(/^\+/, '')} ASC"
|
17
|
+
else
|
18
|
+
"#{attr.strip.gsub(/^\-/, '')} DESC"
|
19
|
+
end
|
20
|
+
end.join(', ')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/senro/version.rb
CHANGED
data/lib/senro.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: senro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WalkerSumida
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- bin/setup
|
73
73
|
- docker-compose.yml
|
74
74
|
- lib/senro.rb
|
75
|
+
- lib/senro/query_params_formatter.rb
|
75
76
|
- lib/senro/version.rb
|
76
77
|
- senro.gemspec
|
77
78
|
homepage: https://github.com/walkersumida/senro
|