hobby 0.2.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 +4 -4
- data/docs/inject_custom_dependencies.md +20 -0
- data/hobby.gemspec +4 -3
- data/lib/hobby.rb +0 -1
- data/lib/hobby/router.rb +9 -6
- data/readme.adoc +7 -23
- data/spec/app_spec.rb +3 -8
- data/spec/apps/Map.rb +0 -3
- data/spec/apps/Nested.rb +1 -1
- data/spec/helper.rb +0 -1
- metadata +7 -8
- data/lib/hobby/router/builder.rb +0 -25
- data/spec/mutant_patches.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
|
@@ -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.2.
|
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
|
|
data/lib/hobby.rb
CHANGED
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,10 +29,8 @@ Or install it yourself as:
|
|
24
29
|
$ gem install hobby
|
25
30
|
----
|
26
31
|
|
27
|
-
[[
|
28
|
-
==
|
29
|
-
|
30
|
-
Hobby provides a Ruby DSL to create web applications. It is well suited both for standalone and inside-Rails use.
|
32
|
+
[[usage]]
|
33
|
+
== Usage
|
31
34
|
|
32
35
|
To create a Hobby application, you create a class and include `Hobby` in it.
|
33
36
|
For example:
|
@@ -299,25 +302,6 @@ class App
|
|
299
302
|
end
|
300
303
|
----
|
301
304
|
|
302
|
-
== Custom components
|
303
|
-
|
304
|
-
Hobby was designed to be very modular.
|
305
|
-
Many components of an application can be customized or replaced.
|
306
|
-
|
307
|
-
[source,ruby]
|
308
|
-
----
|
309
|
-
class App
|
310
|
-
include Hobby
|
311
|
-
|
312
|
-
self.router = custom_router
|
313
|
-
self.request = custom_request
|
314
|
-
self.response = custom_response
|
315
|
-
end
|
316
|
-
----
|
317
|
-
|
318
|
-
TODO: document the API which is expected from each of these components
|
319
|
-
and provide usage examples.
|
320
|
-
|
321
305
|
== Development
|
322
306
|
|
323
307
|
To run the specs:
|
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
|
data/spec/apps/Map.rb
CHANGED
data/spec/apps/Nested.rb
CHANGED
data/spec/helper.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.2.
|
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: 2021-03-
|
11
|
+
date: 2021-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,7 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2'
|
27
|
-
description:
|
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
|
@@ -61,7 +62,6 @@ files:
|
|
61
62
|
- spec/apps/UseInsideInitialize.rb
|
62
63
|
- spec/apps/WithoutPath.rb
|
63
64
|
- spec/helper.rb
|
64
|
-
- spec/mutant_patches.rb
|
65
65
|
- spec/router_matchers.rb
|
66
66
|
- spec/router_spec.rb
|
67
67
|
homepage: https://github.com/ch1c0t/hobby
|
@@ -86,7 +86,7 @@ requirements: []
|
|
86
86
|
rubygems_version: 3.2.3
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
|
-
summary: A
|
89
|
+
summary: A Ruby DSL over Rack.
|
90
90
|
test_files:
|
91
91
|
- spec/app_spec.rb
|
92
92
|
- spec/apps/ContentType.rb
|
@@ -106,6 +106,5 @@ test_files:
|
|
106
106
|
- spec/apps/UseInsideInitialize.rb
|
107
107
|
- spec/apps/WithoutPath.rb
|
108
108
|
- spec/helper.rb
|
109
|
-
- spec/mutant_patches.rb
|
110
109
|
- spec/router_matchers.rb
|
111
110
|
- spec/router_spec.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
|
data/spec/mutant_patches.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# Run all the specs for any subject.
|
2
|
-
class Mutant::Selector::Expression
|
3
|
-
def call _subject
|
4
|
-
integration.all_tests
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
# Do not silence stdout and stderr of the running mutation.
|
9
|
-
class Mutant::Isolation::Fork
|
10
|
-
def result
|
11
|
-
yield
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Print the source of the current mutation.
|
16
|
-
class Mutant::Loader
|
17
|
-
def call
|
18
|
-
source = Unparser.unparse node
|
19
|
-
|
20
|
-
puts <<~S
|
21
|
-
Current mutation:
|
22
|
-
#{source}
|
23
|
-
S
|
24
|
-
|
25
|
-
kernel.eval source, binding, subject.source_path.to_s, subject.source_line
|
26
|
-
end
|
27
|
-
end
|