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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2b39e55ddd774df20a8ba6ff04156303c99bccccb90c08f8915694615faefbe
4
- data.tar.gz: 4c175492dc2b6edf91844b0b826657929d373c6f5985dce4aeb39ca041d70040
3
+ metadata.gz: 5d444c9a283bb890d70f85ab79bbed5c094e9add8ef85b4324525f845b888ec7
4
+ data.tar.gz: 0a4fe7c429e59a98ba20a4f54040e0d715e7acd96f05a75370bf8d453e9642bf
5
5
  SHA512:
6
- metadata.gz: 576536cd9c0e2269658a0d982a92cd2283ca553fa0e95e9725cb40067eda935f8d75753ec9c2ec21b98e0a64b6c3af983591edac6e0aded8a1a28216ec12dec0
7
- data.tar.gz: 0f0e7bb9edde95240b69fcf8447a1d5421e807da3fa8bc8fb38878fc1e7d54d79819709fb18a160b8059f020843b99104bf35fae70fbc10fd27213f938f50228
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.1'
8
- spec.authors = ['Anatoly Chernow']
7
+ spec.version = '0.2.2'
8
+ spec.authors = ['Anatoly Chernov']
9
9
  spec.email = ['chertoly@gmail.com']
10
- spec.summary = %q{A professional way to create Rack applications.}
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
@@ -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
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 = nil, &block
31
- @maps << Builder::Map.new(path, app, &block)
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
- @uses.each { |all| builder.add_use *all }
46
- @maps.each { |map| builder.add_map map }
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
- [[introduction]]
28
- == Introduction
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::App
25
+ include Hobby
26
26
  #{body}
27
27
  end
28
28
  !
29
29
  end
30
30
 
31
- describe Hobby::App do
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::App }
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
@@ -1,5 +1,2 @@
1
1
  map '/map', Proc.new { |env| [200, {}, ['from map']] }
2
- map '/deprecated_map' do
3
- run Proc.new { |env| [200, {}, ['from deprecated map']] }
4
- end
5
2
  get('/') { 'hello world' }
data/spec/apps/Nested.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  nested_app = Class.new do
2
- include Hobby::App
2
+ include Hobby
3
3
 
4
4
  def initialize first, second
5
5
  @a = first
data/spec/helper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'hobby'
2
- require_relative 'mutant_patches' if defined? Mutant
3
2
 
4
3
  require 'minitest'
5
4
  require 'minitest-power_assert'
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
- - Anatoly Chernow
7
+ - Anatoly Chernov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-27 00:00:00.000000000 Z
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 professional way to create Rack applications.
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
@@ -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
@@ -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