hobby 0.1.1 → 0.2.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 +5 -5
- data/.travis.yml +1 -0
- data/Gemfile +1 -2
- data/docs/inject_custom_dependencies.md +20 -0
- data/hobby.gemspec +7 -4
- data/lib/hobby.rb +1 -2
- data/lib/hobby/helpers.rb +5 -1
- data/lib/hobby/router.rb +9 -6
- data/readme.adoc +19 -60
- data/spec/app_spec.rb +13 -8
- data/spec/apps/Map.rb +0 -3
- data/spec/apps/Nested.rb +1 -1
- data/spec/apps/ScriptName.rb +12 -0
- data/spec/helper.rb +0 -29
- data/spec/router_matchers.rb +1 -1
- metadata +15 -13
- data/lib/hobby/router/builder.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5d444c9a283bb890d70f85ab79bbed5c094e9add8ef85b4324525f845b888ec7
|
4
|
+
data.tar.gz: 0a4fe7c429e59a98ba20a4f54040e0d715e7acd96f05a75370bf8d453e9642bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6330ab94e89b3e0e1e53b8f00fbab0e2ca8fc6bdd7cfab85a0d52a317a176f2c74d54195e318020957e0118ba31ba503489e16e93452bf2b094a57ca4616f23a
|
7
|
+
data.tar.gz: 5c0480921249b1ae08c5c9f9e0293d9c593107a0bab9f48e183f806d82a1787a28ac432b5c94e54a79d414681e083a2a99cb336de3800fac315ba2912891bec9
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
You can inject custom dependencies into your apps as follows:
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
class Router < Hobby::Router
|
5
|
+
end
|
6
|
+
|
7
|
+
class Request < Rack::Request
|
8
|
+
end
|
9
|
+
|
10
|
+
class Response < Rack::Response
|
11
|
+
end
|
12
|
+
|
13
|
+
class App
|
14
|
+
include Hobby
|
15
|
+
|
16
|
+
self.router = Router.new
|
17
|
+
self.request = Rack::Request
|
18
|
+
self.response = Rack::Response
|
19
|
+
end
|
20
|
+
```
|
data/hobby.gemspec
CHANGED
@@ -4,10 +4,11 @@ $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.
|
8
|
-
spec.authors = ['Anatoly
|
7
|
+
spec.version = '0.2.2'
|
8
|
+
spec.authors = ['Anatoly Chernov']
|
9
9
|
spec.email = ['chertoly@gmail.com']
|
10
|
-
spec.summary =
|
10
|
+
spec.summary = 'A Ruby DSL over Rack.'
|
11
|
+
spec.description = 'A Ruby DSL over Rack. You can create with it reusable web applications, suitable for both standalone and inside-Rails use.'
|
11
12
|
spec.homepage = 'https://github.com/ch1c0t/hobby'
|
12
13
|
spec.license = 'MIT'
|
13
14
|
|
@@ -16,5 +17,7 @@ Gem::Specification.new do |spec|
|
|
16
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
18
|
spec.require_paths = ['lib']
|
18
19
|
|
19
|
-
spec.add_dependency 'rack'
|
20
|
+
spec.add_dependency 'rack', '~> 2'
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.6.6'
|
20
23
|
end
|
data/lib/hobby.rb
CHANGED
@@ -5,7 +5,6 @@ require 'hobby/router'
|
|
5
5
|
require 'hobby/helpers'
|
6
6
|
|
7
7
|
module Hobby
|
8
|
-
App = Hobby # to stay compatible with old code
|
9
8
|
VERBS = %w[DELETE GET HEAD OPTIONS PATCH POST PUT]
|
10
9
|
|
11
10
|
def self.included app
|
@@ -42,7 +41,7 @@ module Hobby
|
|
42
41
|
catch :halt do
|
43
42
|
@route = router.route_for (@env = env)
|
44
43
|
fill_body
|
45
|
-
response
|
44
|
+
response.to_a
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
data/lib/hobby/helpers.rb
CHANGED
@@ -27,7 +27,7 @@ module Hobby
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def halt
|
30
|
-
throw :halt, response
|
30
|
+
throw :halt, response.to_a
|
31
31
|
end
|
32
32
|
|
33
33
|
def not_found
|
@@ -42,5 +42,9 @@ module Hobby
|
|
42
42
|
def status status
|
43
43
|
response.status = status
|
44
44
|
end
|
45
|
+
|
46
|
+
def script_name
|
47
|
+
env.fetch 'SCRIPT_NAME'
|
48
|
+
end
|
45
49
|
end
|
46
50
|
end
|
data/lib/hobby/router.rb
CHANGED
@@ -27,8 +27,8 @@ module Hobby
|
|
27
27
|
@uses << all
|
28
28
|
end
|
29
29
|
|
30
|
-
def map path, app
|
31
|
-
@maps <<
|
30
|
+
def map path, app
|
31
|
+
@maps << [path, app]
|
32
32
|
end
|
33
33
|
|
34
34
|
attr_accessor :app
|
@@ -41,14 +41,17 @@ module Hobby
|
|
41
41
|
|
42
42
|
private
|
43
43
|
def create_builder
|
44
|
-
builder = Builder.new
|
45
|
-
|
46
|
-
@
|
44
|
+
builder = Rack::Builder.new
|
45
|
+
|
46
|
+
@uses.each { |all| builder.use *all }
|
47
|
+
@maps.each { |path, app|
|
48
|
+
builder.map path do run app end
|
49
|
+
}
|
50
|
+
|
47
51
|
builder
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
52
|
-
require 'hobby/router/builder'
|
53
56
|
require 'hobby/router/routes'
|
54
57
|
require 'hobby/router/route'
|
data/readme.adoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
[[introduction]]
|
2
|
+
== Introduction
|
3
|
+
|
4
|
+
A Ruby DSL over Rack. You can create with it reusable web applications, suitable for both standalone and inside-Rails use.
|
5
|
+
|
1
6
|
[[installation]]
|
2
7
|
== Installation
|
3
8
|
|
@@ -24,11 +29,8 @@ Or install it yourself as:
|
|
24
29
|
$ gem install hobby
|
25
30
|
----
|
26
31
|
|
27
|
-
[[
|
28
|
-
==
|
29
|
-
|
30
|
-
Hobby features a Sinatra-like DSL, but in contrast to Sinatra,
|
31
|
-
Hobby applications behave like usual Ruby classes.
|
32
|
+
[[usage]]
|
33
|
+
== Usage
|
32
34
|
|
33
35
|
To create a Hobby application, you create a class and include `Hobby` in it.
|
34
36
|
For example:
|
@@ -40,9 +42,9 @@ require 'hobby'
|
|
40
42
|
class C
|
41
43
|
include Hobby
|
42
44
|
|
43
|
-
get
|
45
|
+
get "/hello" do
|
44
46
|
"Hello, world."
|
45
|
-
|
47
|
+
end
|
46
48
|
end
|
47
49
|
----
|
48
50
|
|
@@ -74,9 +76,9 @@ class C
|
|
74
76
|
@name = name
|
75
77
|
end
|
76
78
|
|
77
|
-
get
|
79
|
+
get "/hello" do
|
78
80
|
"Hello, #{@name}."
|
79
|
-
|
81
|
+
end
|
80
82
|
end
|
81
83
|
----
|
82
84
|
|
@@ -95,9 +97,9 @@ class C
|
|
95
97
|
@name.upcase
|
96
98
|
end
|
97
99
|
|
98
|
-
get
|
100
|
+
get "/hello" do
|
99
101
|
"Hello, #{name}."
|
100
|
-
|
102
|
+
end
|
101
103
|
end
|
102
104
|
----
|
103
105
|
|
@@ -133,29 +135,12 @@ For common HTTP verbs, Hobby provides the route definers(methods named according
|
|
133
135
|
class App
|
134
136
|
include Hobby
|
135
137
|
|
136
|
-
get '
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
put '/' do
|
145
|
-
# ...
|
146
|
-
end
|
147
|
-
|
148
|
-
patch '/' do
|
149
|
-
# ...
|
150
|
-
end
|
151
|
-
|
152
|
-
delete '/' do
|
153
|
-
# ...
|
154
|
-
end
|
155
|
-
|
156
|
-
options '/' do
|
157
|
-
# ...
|
158
|
-
end
|
138
|
+
get { 'Some string.' }
|
139
|
+
post { 'Some string.' }
|
140
|
+
put { 'Some string.' }
|
141
|
+
patch { 'Some string.' }
|
142
|
+
delete { 'Some string.' }
|
143
|
+
# TODO: find a good example for `options`
|
159
144
|
end
|
160
145
|
----
|
161
146
|
|
@@ -317,25 +302,6 @@ class App
|
|
317
302
|
end
|
318
303
|
----
|
319
304
|
|
320
|
-
== Custom components
|
321
|
-
|
322
|
-
Hobby was designed to be very modular.
|
323
|
-
Many components of an application can be customized or replaced.
|
324
|
-
|
325
|
-
[source,ruby]
|
326
|
-
----
|
327
|
-
class App
|
328
|
-
include Hobby
|
329
|
-
|
330
|
-
self.router = custom_router
|
331
|
-
self.request = custom_request
|
332
|
-
self.response = custom_response
|
333
|
-
end
|
334
|
-
----
|
335
|
-
|
336
|
-
TODO: document the API which is expected from each of these components
|
337
|
-
and provide usage examples.
|
338
|
-
|
339
305
|
== Development
|
340
306
|
|
341
307
|
To run the specs:
|
@@ -344,10 +310,3 @@ To run the specs:
|
|
344
310
|
----
|
345
311
|
bundle exec rspec
|
346
312
|
----
|
347
|
-
|
348
|
-
To perform mutation analysis:
|
349
|
-
|
350
|
-
[source,bash]
|
351
|
-
----
|
352
|
-
bundle exec mutant --use rspec 'Hobby*'
|
353
|
-
----
|
data/spec/app_spec.rb
CHANGED
@@ -22,13 +22,13 @@ def build_app described_class
|
|
22
22
|
|
23
23
|
eval %!
|
24
24
|
Class.new do
|
25
|
-
include Hobby
|
25
|
+
include Hobby
|
26
26
|
#{body}
|
27
27
|
end
|
28
28
|
!
|
29
29
|
end
|
30
30
|
|
31
|
-
describe Hobby
|
31
|
+
describe Hobby do
|
32
32
|
include Rack::Test::Methods
|
33
33
|
|
34
34
|
describe '.new' do
|
@@ -39,7 +39,7 @@ describe Hobby::App do
|
|
39
39
|
|
40
40
|
context 'an app without nested app(s)' do
|
41
41
|
let(:subject) { build_app(Main).new }
|
42
|
-
it { should be_a Hobby
|
42
|
+
it { should be_a Hobby }
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -100,11 +100,6 @@ describe Hobby::App do
|
|
100
100
|
get '/map'
|
101
101
|
assert { last_response.body == 'from map' }
|
102
102
|
end
|
103
|
-
|
104
|
-
it 'mounts an application to the rack stack with old deprecated syntax' do
|
105
|
-
get '/deprecated_map'
|
106
|
-
assert { last_response.body == 'from deprecated map' }
|
107
|
-
end
|
108
103
|
end
|
109
104
|
|
110
105
|
describe MapInsideInitialize do
|
@@ -272,5 +267,15 @@ describe Hobby::App do
|
|
272
267
|
assert { last_response.content_type == 'application/html' }
|
273
268
|
end
|
274
269
|
end
|
270
|
+
|
271
|
+
describe ScriptName do
|
272
|
+
it do
|
273
|
+
get '/'
|
274
|
+
assert { last_response.body == '' }
|
275
|
+
|
276
|
+
get '/some/path'
|
277
|
+
assert { last_response.body == '/some/path' }
|
278
|
+
end
|
279
|
+
end
|
275
280
|
end
|
276
281
|
end
|
data/spec/apps/Map.rb
CHANGED
data/spec/apps/Nested.rb
CHANGED
data/spec/helper.rb
CHANGED
@@ -1,38 +1,9 @@
|
|
1
|
-
require 'devtools/spec_helper'
|
2
|
-
|
3
1
|
require 'hobby'
|
4
2
|
|
5
3
|
require 'minitest'
|
6
4
|
require 'minitest-power_assert'
|
7
5
|
Minitest::Assertions.prepend Minitest::PowerAssert::Assertions
|
8
6
|
|
9
|
-
if defined? Mutant
|
10
|
-
class Mutant::Selector::Expression
|
11
|
-
def call _subject
|
12
|
-
integration.all_tests
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Mutant::Isolation::Fork
|
17
|
-
def result
|
18
|
-
yield
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Mutant::Loader
|
23
|
-
def call
|
24
|
-
source = Unparser.unparse node
|
25
|
-
|
26
|
-
puts <<~S
|
27
|
-
Current mutantion:
|
28
|
-
#{source}
|
29
|
-
S
|
30
|
-
|
31
|
-
kernel.eval source, binding, subject.source_path.to_s, subject.source_line
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
7
|
module EnvFor
|
37
8
|
def env_for path, verb = 'GET'
|
38
9
|
{'REQUEST_METHOD' => verb, 'PATH_INFO' => path }
|
data/spec/router_matchers.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Anatoly
|
7
|
+
- Anatoly Chernov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
description:
|
26
|
+
version: '2'
|
27
|
+
description: A Ruby DSL over Rack. You can create with it reusable web applications,
|
28
|
+
suitable for both standalone and inside-Rails use.
|
28
29
|
email:
|
29
30
|
- chertoly@gmail.com
|
30
31
|
executables: []
|
@@ -35,11 +36,11 @@ files:
|
|
35
36
|
- ".travis.yml"
|
36
37
|
- Gemfile
|
37
38
|
- LICENSE
|
39
|
+
- docs/inject_custom_dependencies.md
|
38
40
|
- hobby.gemspec
|
39
41
|
- lib/hobby.rb
|
40
42
|
- lib/hobby/helpers.rb
|
41
43
|
- lib/hobby/router.rb
|
42
|
-
- lib/hobby/router/builder.rb
|
43
44
|
- lib/hobby/router/route.rb
|
44
45
|
- lib/hobby/router/routes.rb
|
45
46
|
- readme.adoc
|
@@ -53,6 +54,7 @@ files:
|
|
53
54
|
- spec/apps/MapInsideInitialize.rb
|
54
55
|
- spec/apps/Nested.rb
|
55
56
|
- spec/apps/OneRouteRouter.rb
|
57
|
+
- spec/apps/ScriptName.rb
|
56
58
|
- spec/apps/Status.rb
|
57
59
|
- spec/apps/UnshareableRouterMaps.rb
|
58
60
|
- spec/apps/UnshareableRouterUses.rb
|
@@ -74,18 +76,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
76
|
requirements:
|
75
77
|
- - ">="
|
76
78
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
79
|
+
version: 2.6.6
|
78
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
81
|
requirements:
|
80
82
|
- - ">="
|
81
83
|
- !ruby/object:Gem::Version
|
82
84
|
version: '0'
|
83
85
|
requirements: []
|
84
|
-
|
85
|
-
rubygems_version: 2.6.13
|
86
|
+
rubygems_version: 3.2.3
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
|
-
summary: A
|
89
|
+
summary: A Ruby DSL over Rack.
|
89
90
|
test_files:
|
90
91
|
- spec/app_spec.rb
|
91
92
|
- spec/apps/ContentType.rb
|
@@ -97,6 +98,7 @@ test_files:
|
|
97
98
|
- spec/apps/MapInsideInitialize.rb
|
98
99
|
- spec/apps/Nested.rb
|
99
100
|
- spec/apps/OneRouteRouter.rb
|
101
|
+
- spec/apps/ScriptName.rb
|
100
102
|
- spec/apps/Status.rb
|
101
103
|
- spec/apps/UnshareableRouterMaps.rb
|
102
104
|
- spec/apps/UnshareableRouterUses.rb
|
data/lib/hobby/router/builder.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Hobby
|
2
|
-
class Router
|
3
|
-
class Builder < Rack::Builder
|
4
|
-
# To work around
|
5
|
-
# https://github.com/mbj/mutant#the-crash--stuck-problem-mri
|
6
|
-
alias add_use use
|
7
|
-
alias add_map2 map
|
8
|
-
|
9
|
-
def add_map map
|
10
|
-
if map.app
|
11
|
-
add_map2 map.path do run map.app end
|
12
|
-
else
|
13
|
-
add_map2 map.path, &map.block
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Map
|
18
|
-
attr_reader :path, :app, :block
|
19
|
-
def initialize path, app, &block
|
20
|
-
@path, @app, @block = path, app, block
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|