hobby 0.0.1 → 0.0.2
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 +4 -4
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/hobby.gemspec +3 -3
- data/lib/hobby/app.rb +3 -3
- data/lib/hobby/router/route.rb +12 -0
- data/lib/hobby/router/routes.rb +24 -0
- data/lib/hobby/router.rb +8 -24
- data/lib/hobby/rspec/router.rb +2 -2
- data/lib/hobby.rb +1 -1
- data/spec/app_spec.rb +7 -0
- data/spec/apps/Decorator.rb +6 -0
- data/spec/apps/Main.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7bc8b664dad60ba755a291e2b6ecac6e330b227
|
4
|
+
data.tar.gz: 2dce16045fe1301e04a45b6057787b2b036b9332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1088888933b0786921737b63f546110078a91372bfc59db7b266efdfcf8e796c59f3e4cc28c5678030541583d9f59ea7d61b633b2e1f8e5c2f169fc16e85f3
|
7
|
+
data.tar.gz: 2874923dffc328ff549ba1d7e2104ba170722a2a5a0f93ffb6276607153489a1b9ca7bd67f263a3b9c4274e80eab9cd302ec558ad762c7b3e3255a40c563ffba
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/hobby.gemspec
CHANGED
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'hobby'
|
7
|
-
spec.version = '0.0.
|
8
|
-
spec.authors = ['Anatoly
|
9
|
-
spec.email = ['
|
7
|
+
spec.version = '0.0.2'
|
8
|
+
spec.authors = ['Anatoly Chernow']
|
9
|
+
spec.email = ['chertoly@gmail.com']
|
10
10
|
spec.summary = %q{A minimal DSL over rack}
|
11
11
|
spec.homepage = 'https://github.com/ch1c0t/hobby'
|
12
12
|
spec.license = 'MIT'
|
data/lib/hobby/app.rb
CHANGED
@@ -17,9 +17,9 @@ module Hobby
|
|
17
17
|
extend Forwardable
|
18
18
|
delegate [:map, :use] => :builder
|
19
19
|
|
20
|
-
|
21
|
-
define_method verb.downcase do |path = '/', &
|
22
|
-
router.add_route verb, path, &
|
20
|
+
VERBS.each do |verb|
|
21
|
+
define_method verb.downcase do |path = '/', &action|
|
22
|
+
router.add_route verb, path, &action
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Hobby::Router
|
2
|
+
class Routes < Hash
|
3
|
+
def initialize
|
4
|
+
@patterns = {}
|
5
|
+
super { |hash, key| hash[key] = find key }
|
6
|
+
end
|
7
|
+
|
8
|
+
def []= key, route
|
9
|
+
if key.include? ?:
|
10
|
+
string = key.gsub(/(:\w+)/) { "(?<#{$1[1..-1]}>[^/?#]+)" }
|
11
|
+
@patterns[/^#{string}$/] = route
|
12
|
+
else
|
13
|
+
super and super "#{key}/", route
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def find key
|
20
|
+
_, route = @patterns.find { |pattern, _| pattern.match key }
|
21
|
+
[route, $~.names.map(&:to_sym).zip($~.captures).to_h] if route
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/hobby/router.rb
CHANGED
@@ -4,9 +4,13 @@ module Hobby
|
|
4
4
|
@routes = Routes.new
|
5
5
|
end
|
6
6
|
|
7
|
-
def add_route verb, path, &
|
7
|
+
def add_route verb, path, &action
|
8
|
+
route = Route.new verb, path, &action
|
9
|
+
|
8
10
|
path = nil if path.eql? '/'
|
9
11
|
@routes["#{verb}#{path}"] = route
|
12
|
+
|
13
|
+
route
|
10
14
|
end
|
11
15
|
|
12
16
|
def route_for env
|
@@ -14,28 +18,8 @@ module Hobby
|
|
14
18
|
env[:path_params] = params if params
|
15
19
|
route
|
16
20
|
end
|
17
|
-
|
18
|
-
class Routes < Hash
|
19
|
-
def initialize
|
20
|
-
@patterns = {}
|
21
|
-
super { |hash, key| hash[key] = find key }
|
22
|
-
end
|
23
|
-
|
24
|
-
def []= key, route
|
25
|
-
if key.include? ?:
|
26
|
-
string = key.gsub(/(:\w+)/) { "(?<#{$1[1..-1]}>[^/?#]+)" }
|
27
|
-
@patterns[/^#{string}$/] = route
|
28
|
-
else
|
29
|
-
super and super "#{key}/", route
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def find key
|
36
|
-
_, route = @patterns.find { |pattern, _| pattern.match key }
|
37
|
-
[route, $~.names.map(&:to_sym).zip($~.captures).to_h] if route
|
38
|
-
end
|
39
|
-
end
|
40
21
|
end
|
41
22
|
end
|
23
|
+
|
24
|
+
require 'hobby/router/routes'
|
25
|
+
require 'hobby/router/route'
|
data/lib/hobby/rspec/router.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Hobby::RSpec
|
2
2
|
module Router
|
3
3
|
extend self
|
4
|
-
SOME_ROUTE = ->{}
|
4
|
+
SOME_ROUTE = ->{:some_route}
|
5
5
|
|
6
6
|
def env_for path, verb = 'GET'
|
7
7
|
{'REQUEST_METHOD' => verb, 'PATH_INFO' => path }
|
@@ -20,7 +20,7 @@ module Hobby::RSpec
|
|
20
20
|
|
21
21
|
params_are_ok = (@params ? (@params.to_a - env[:path_params].to_a).empty? : true)
|
22
22
|
|
23
|
-
(route == SOME_ROUTE) && params_are_ok
|
23
|
+
route && (route.to_proc.call == SOME_ROUTE.call) && params_are_ok
|
24
24
|
end
|
25
25
|
|
26
26
|
chain :and_set_params do |**params|
|
data/lib/hobby.rb
CHANGED
data/spec/app_spec.rb
CHANGED
data/spec/apps/Main.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Anatoly
|
7
|
+
- Anatoly Chernow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
version: '0'
|
27
27
|
description:
|
28
28
|
email:
|
29
|
-
-
|
29
|
+
- chertoly@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
@@ -42,8 +42,11 @@ files:
|
|
42
42
|
- lib/hobby.rb
|
43
43
|
- lib/hobby/app.rb
|
44
44
|
- lib/hobby/router.rb
|
45
|
+
- lib/hobby/router/route.rb
|
46
|
+
- lib/hobby/router/routes.rb
|
45
47
|
- lib/hobby/rspec/router.rb
|
46
48
|
- spec/app_spec.rb
|
49
|
+
- spec/apps/Decorator.rb
|
47
50
|
- spec/apps/Env.rb
|
48
51
|
- spec/apps/Main.rb
|
49
52
|
- spec/apps/Map.rb
|
@@ -74,12 +77,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
77
|
version: '0'
|
75
78
|
requirements: []
|
76
79
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.5.
|
80
|
+
rubygems_version: 2.5.2
|
78
81
|
signing_key:
|
79
82
|
specification_version: 4
|
80
83
|
summary: A minimal DSL over rack
|
81
84
|
test_files:
|
82
85
|
- spec/app_spec.rb
|
86
|
+
- spec/apps/Decorator.rb
|
83
87
|
- spec/apps/Env.rb
|
84
88
|
- spec/apps/Main.rb
|
85
89
|
- spec/apps/Map.rb
|