makanai 0.1.3 → 0.1.4

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
2
  SHA256:
3
- metadata.gz: 50ec7b4b39d4f324b5bb6d2c36c0f9f03274fd5b224862b4142d28cde7950a0f
4
- data.tar.gz: d3b3716c39366f43b142c67f82ab7763ce6b65d07e3ef19a40347a56c71920a7
3
+ metadata.gz: 607ef9008aa96fb7c280d3c0008997ad827167bc3a304ba89ca31f7300ce055d
4
+ data.tar.gz: '096ca3a1b65a84402d5872c548d8c6cd5d339a10e680fa335b0e5fd84b3cdb6e'
5
5
  SHA512:
6
- metadata.gz: 181e579b7e1d48853f06756c1f23f74b4ed15bcc083ac504df6fc716010ce99b3552216ebea3854a484a35256d6e7ef69031c2b8cc11c5d5c6165fcef3e53bc0
7
- data.tar.gz: ed57e62dabd988e754728cd7677bfb397e1836bd499cde76ebaed7ccc27849e728fed84b473eb325ba7cb5e527d97a52cdcdf4cef183df4cb295f348827efae3
6
+ metadata.gz: ed2c690d61a98de06ebdeee12f5a8bc5d51941265dd547b6fe26f09606f7c13081a137b7ed95b83e78c170bdc59791ff30c1e01cf0dc6ae3304db6a1e9f49ce2
7
+ data.tar.gz: 2290b7bbf2b392853a9d133392e5d69e4103a457b008254eb735036e5c0a41064c95633fa10389d9cf5987d637d5046b2d981c8e0f54b524de68c07a9d29fe74
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
 
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
+ /**/.DS_Store
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.1
data/.travis.yml CHANGED
@@ -1,14 +1,20 @@
1
1
  ---
2
- sudo: false
3
2
  language: ruby
4
3
  cache: bundler
5
4
  services:
6
5
  - postgresql
7
6
  - mysql
8
7
  rvm:
9
- - 2.7.0
8
+ - 2.6.6
9
+ - 2.7.1
10
+ - ruby-head
11
+ os:
12
+ - linux
10
13
  before_install:
11
- - gem install bundler -v 2.0.2
14
+ - gem install bundler -v 2.1.4
12
15
  - mysql -e 'CREATE DATABASE IF NOT EXISTS makanai;'
13
16
  before_script:
14
17
  - psql -c 'create database makanai;' -U postgres
18
+ jobs:
19
+ allow_failures:
20
+ - rvm: ruby-head
data/CHANGELOG.md CHANGED
@@ -24,3 +24,15 @@
24
24
  * :sparkles: Multiple DBMS available.
25
25
  you can use dbms(MySQL :dolphin:, PostgreSQL :elephant:) other then SQLite.
26
26
  https://github.com/Madogiwa0124/makanai/pull/19
27
+
28
+ ## :gift: 2020/04/08 `v0.1.4` released.
29
+ * :sparkles: support lastest ruby versions(2.6.6, 2.7.1)
30
+ * :sparkles: support for dynamic URL routing.
31
+
32
+ ``` ruby
33
+ router.get '/hoge/:id' do
34
+ request.params['id']
35
+ end
36
+ ```
37
+
38
+ https://github.com/Madogiwa0124/makanai/commit/e256368fd0a13f1d0d2d6c6af17caef7760e64f0
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ source 'https://rubygems.org'
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  gemspec
8
+
9
+ gem 'codecov', :require => false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- makanai (0.1.3)
4
+ makanai (0.1.4)
5
5
  rack (>= 2.0.7, < 2.3.0)
6
6
  rake (>= 10, < 14)
7
7
  sqlite3 (~> 1.4.1)
@@ -10,13 +10,19 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.0)
13
+ codecov (0.1.16)
14
+ json
15
+ simplecov
16
+ url
13
17
  diff-lcs (1.3)
18
+ docile (1.3.2)
14
19
  jaro_winkler (1.5.4)
20
+ json (2.3.0)
15
21
  mysql2 (0.5.3)
16
22
  parallel (1.19.1)
17
- parser (2.7.0.4)
23
+ parser (2.7.1.0)
18
24
  ast (~> 2.4.0)
19
- pg (1.2.2)
25
+ pg (1.2.3)
20
26
  rack (2.2.2)
21
27
  rainbow (3.0.0)
22
28
  rake (13.0.1)
@@ -25,32 +31,38 @@ GEM
25
31
  rspec-core (~> 3.9.0)
26
32
  rspec-expectations (~> 3.9.0)
27
33
  rspec-mocks (~> 3.9.0)
28
- rspec-core (3.9.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-expectations (3.9.0)
34
+ rspec-core (3.9.1)
35
+ rspec-support (~> 3.9.1)
36
+ rspec-expectations (3.9.1)
31
37
  diff-lcs (>= 1.2.0, < 2.0)
32
38
  rspec-support (~> 3.9.0)
33
- rspec-mocks (3.9.0)
39
+ rspec-mocks (3.9.1)
34
40
  diff-lcs (>= 1.2.0, < 2.0)
35
41
  rspec-support (~> 3.9.0)
36
- rspec-support (3.9.0)
37
- rubocop (0.80.1)
42
+ rspec-support (3.9.2)
43
+ rubocop (0.81.0)
38
44
  jaro_winkler (~> 1.5.1)
39
45
  parallel (~> 1.10)
40
46
  parser (>= 2.7.0.1)
41
47
  rainbow (>= 2.2.2, < 4.0)
42
48
  rexml
43
49
  ruby-progressbar (~> 1.7)
44
- unicode-display_width (>= 1.4.0, < 1.7)
50
+ unicode-display_width (>= 1.4.0, < 2.0)
45
51
  ruby-progressbar (1.10.1)
52
+ simplecov (0.18.5)
53
+ docile (~> 1.1)
54
+ simplecov-html (~> 0.11)
55
+ simplecov-html (0.12.2)
46
56
  sqlite3 (1.4.2)
47
- unicode-display_width (1.6.1)
57
+ unicode-display_width (1.7.0)
58
+ url (0.3.2)
48
59
 
49
60
  PLATFORMS
50
61
  ruby
51
62
 
52
63
  DEPENDENCIES
53
64
  bundler (~> 2.0)
65
+ codecov
54
66
  makanai!
55
67
  mysql2 (~> 0.5)
56
68
  pg (~> 1.2)
@@ -58,4 +70,4 @@ DEPENDENCIES
58
70
  rubocop (~> 0.74)
59
71
 
60
72
  BUNDLED WITH
61
- 2.1.2
73
+ 2.1.4
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/makanai.svg)](https://badge.fury.io/rb/makanai)
4
4
  [![Build Status](https://travis-ci.com/Madogiwa0124/makanai.svg?branch=master)](https://travis-ci.com/Madogiwa0124/makanai)
5
+ [![codecov](https://codecov.io/gh/Madogiwa0124/makanai/branch/master/graph/badge.svg)](https://codecov.io/gh/Madogiwa0124/makanai)
5
6
 
6
7
  simple web application framework for learning.
7
8
 
@@ -121,6 +122,7 @@ Makanai::Settings.databse_config = {
121
122
  ```
122
123
 
123
124
  ## routing
125
+ Routing is searched in the order defined and call block args.
124
126
 
125
127
  ``` ruby
126
128
  require 'makanai/main'
@@ -135,11 +137,17 @@ router.get '/hoge' do
135
137
  'Hello Hoge!'
136
138
  end
137
139
 
138
- # enable access to /params with get parameter
139
- router.get '/check' do |request|
140
+ # enable access to /hoge with get parameter(?hoge=fuga)
141
+ router.get '/hoge' do |request|
140
142
  request.params['hoge']
141
143
  end
142
144
 
145
+ # enable access to /hoge/:id with dinamic url args({ 'id' => '1'})
146
+ # NOTE: dinamics prefix is `:`.
147
+ router.get '/hoge/:id' do
148
+ request.params['id']
149
+ end
150
+
143
151
  # enable access to /resources with method post and redirect other url.
144
152
  router.post '/resources' do |request|
145
153
  Resource.new(request.params).create
@@ -38,7 +38,10 @@ module Makanai
38
38
  private
39
39
 
40
40
  def execute_route
41
- router.bind!(url: request.url, method: request.method).process.call(request)
41
+ route = router.bind!(url: request.url, method: request.method)
42
+ # NOTE: merge dynamic url params (ex. /resources/1 -> { 'id' => '1' })
43
+ @request.params.merge!(route.url_args)
44
+ route.process.call(request)
42
45
  rescue Makanai::Router::NotFound
43
46
  @response.status = 404
44
47
  nil
@@ -6,7 +6,8 @@ require 'uri'
6
6
 
7
7
  module Makanai
8
8
  class Request < Rack::Request
9
- attr_reader :env, :url, :query, :origin_body, :method, :params
9
+ attr_reader :env, :url, :query, :origin_body, :method
10
+ attr_accessor :params
10
11
 
11
12
  def initialize(env)
12
13
  super
@@ -30,19 +30,50 @@ module Makanai
30
30
 
31
31
  def bind!(url:, method:)
32
32
  path = URI.parse(url).path
33
- routes.find { |route| route.path == path && route.method == method }.tap do |route|
33
+ routes.find { |route| route.match?(path: path, method: method) }.tap do |route|
34
34
  raise NotFound if route.nil?
35
35
  end
36
36
  end
37
37
 
38
38
  class Route
39
+ DYNAMIC_PREFIX = ':' # Prefix for dynamic path
40
+
39
41
  def initialize(path:, process:, method:)
40
42
  @path = path
41
43
  @process = process
42
44
  @method = method
45
+ @url_args = {}
46
+ end
47
+
48
+ attr_reader :path, :process, :method, :url_args
49
+
50
+ def match?(path:, method:)
51
+ build_url_args(path: path)
52
+ path_match?(path) && self.method == method
53
+ end
54
+
55
+ private
56
+
57
+ def dynamic_indx
58
+ @dynamic_indx ||= path.split('/').map.with_index do |val, i|
59
+ i if val.include?(DYNAMIC_PREFIX)
60
+ end.compact
43
61
  end
44
62
 
45
- attr_reader :path, :process, :method
63
+ def path_match?(path)
64
+ request_path, route_path = [path, self.path].map(&->(array) { array.split('/') })
65
+ request_path.each.with_index do |val, i|
66
+ route_path[i] = val if dynamic_indx.include?(i)
67
+ end
68
+ route_path == request_path
69
+ end
70
+
71
+ def build_url_args(path:)
72
+ request_path, route_path = [path, self.path].map(&->(array) { array.split('/') })
73
+ dynamic_indx.each do |i|
74
+ @url_args.merge!({ route_path[i].gsub(DYNAMIC_PREFIX, '') => request_path[i] })
75
+ end
76
+ end
46
77
  end
47
78
  end
48
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Makanai
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: makanai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Madogiwa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-04 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -145,6 +145,7 @@ files:
145
145
  - ".gitignore"
146
146
  - ".rspec"
147
147
  - ".rubocop.yml"
148
+ - ".ruby-version"
148
149
  - ".travis.yml"
149
150
  - CHANGELOG.md
150
151
  - CODE_OF_CONDUCT.md