senro 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10964b6ce3d0e2b59195d2b4b031e6609b149d2c1165623c29b89e896a47165d
4
- data.tar.gz: 46ef1957e269fdd3855f60a35854ca8ad4b1fdaaa51e46472ac9406fccd7f5c6
3
+ metadata.gz: 696fbf72ba815d79a7698e65507dc96be100474f9c9c7206500784b054c4b224
4
+ data.tar.gz: 5f93be5e568bde5cd1ab13c60995721715deefc7c3d77350ba8085102e112b18
5
5
  SHA512:
6
- metadata.gz: 260ba7196b7e6d75a1c499320a0654771c3cb4d5695b367c60bcdcc5877055e97b8bb12c374ccb5066690d5e2dc950ec82ee130303c05e91d78283920374cc8e
7
- data.tar.gz: cfbc66c765dcc20437a7bd16b35855c003509ac9cd89b6f762826d1fdce88853c04f2a34c473d1fccf61d69aa95f0eff4dd69552d0ec2c16f3db6066103a56d4
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.6.5
7
- before_install: gem install bundler -v 1.17.2
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/senro`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Senro
2
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
3
5
  end
data/lib/senro.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "senro/version"
2
+ require 'senro/query_params_formatter'
2
3
 
3
4
  module Senro
4
- class Error < StandardError; end
5
- # Your code goes here...
6
5
  end
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.1.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-04 00:00:00.000000000 Z
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