hobby 0.1.0 → 0.2.1

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
- SHA1:
3
- metadata.gz: 1c820bc2f67ffcbd87d4de89a2e8ad53a6f83da9
4
- data.tar.gz: e56880e61b2d283537bf44bd019709440dde9118
2
+ SHA256:
3
+ metadata.gz: d2b39e55ddd774df20a8ba6ff04156303c99bccccb90c08f8915694615faefbe
4
+ data.tar.gz: 4c175492dc2b6edf91844b0b826657929d373c6f5985dce4aeb39ca041d70040
5
5
  SHA512:
6
- metadata.gz: f14f9c47364424a1826184cd11a670eed4509e315bb83b6f978e05022fd17da57d3fc139d1e40c62ea33c06ebf59c38996f4dfb90ea0bef779b2a67b837321b5
7
- data.tar.gz: 27b2ac428b2a8a7b51941a4e4dd7bab6d9c28e1cbbb4e77d49c282ce58638e0500913b6320f2090511a4a5ca7793b9ba1afd9099748ba17b67afde31214b3142
6
+ metadata.gz: 576536cd9c0e2269658a0d982a92cd2283ca553fa0e95e9725cb40067eda935f8d75753ec9c2ec21b98e0a64b6c3af983591edac6e0aded8a1a28216ec12dec0
7
+ data.tar.gz: 0f0e7bb9edde95240b69fcf8447a1d5421e807da3fa8bc8fb38878fc1e7d54d79819709fb18a160b8059f020843b99104bf35fae70fbc10fd27213f938f50228
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.5
4
5
  - 2.4
5
6
  - 2.3
6
7
  script: bundle exec rspec
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'devtools'
4
- gem 'mutant'
3
+ gem 'rspec'
5
4
  gem 'minitest'
6
5
  gem 'minitest-power_assert'
7
6
  gem 'rack-test'
data/hobby.gemspec CHANGED
@@ -4,10 +4,10 @@ $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.1.0'
7
+ spec.version = '0.2.1'
8
8
  spec.authors = ['Anatoly Chernow']
9
9
  spec.email = ['chertoly@gmail.com']
10
- spec.summary = %q{A minimal DSL over rack}
10
+ spec.summary = %q{A professional way to create Rack applications.}
11
11
  spec.homepage = 'https://github.com/ch1c0t/hobby'
12
12
  spec.license = 'MIT'
13
13
 
@@ -16,5 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ['lib']
18
18
 
19
- spec.add_dependency 'rack'
19
+ spec.add_dependency 'rack', '~> 2'
20
+
21
+ spec.required_ruby_version = '>= 2.6.6'
20
22
  end
data/lib/hobby.rb CHANGED
@@ -42,7 +42,7 @@ module Hobby
42
42
  catch :halt do
43
43
  @route = router.route_for (@env = env)
44
44
  fill_body
45
- response
45
+ response.to_a
46
46
  end
47
47
  end
48
48
 
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
@@ -6,8 +6,7 @@ module Hobby
6
6
  end
7
7
 
8
8
  def initialize_copy _router
9
- @uses = instance_variable_get(:@uses).dup
10
- @maps = instance_variable_get(:@maps).dup
9
+ @uses, @maps = @uses.dup, @maps.dup
11
10
  end
12
11
 
13
12
  def add_route verb, path, &action
data/readme.adoc CHANGED
@@ -27,8 +27,7 @@ $ gem install hobby
27
27
  [[introduction]]
28
28
  == Introduction
29
29
 
30
- Hobby features a Sinatra-like DSL, but in contrast to Sinatra,
31
- Hobby applications behave like usual Ruby classes.
30
+ Hobby provides a Ruby DSL to create web applications. It is well suited both for standalone and inside-Rails use.
32
31
 
33
32
  To create a Hobby application, you create a class and include `Hobby` in it.
34
33
  For example:
@@ -40,9 +39,9 @@ require 'hobby'
40
39
  class C
41
40
  include Hobby
42
41
 
43
- get("/hello") {
42
+ get "/hello" do
44
43
  "Hello, world."
45
- }
44
+ end
46
45
  end
47
46
  ----
48
47
 
@@ -74,9 +73,9 @@ class C
74
73
  @name = name
75
74
  end
76
75
 
77
- get("/hello") {
76
+ get "/hello" do
78
77
  "Hello, #{@name}."
79
- }
78
+ end
80
79
  end
81
80
  ----
82
81
 
@@ -95,9 +94,9 @@ class C
95
94
  @name.upcase
96
95
  end
97
96
 
98
- get("/hello") {
97
+ get "/hello" do
99
98
  "Hello, #{name}."
100
- }
99
+ end
101
100
  end
102
101
  ----
103
102
 
@@ -133,29 +132,12 @@ For common HTTP verbs, Hobby provides the route definers(methods named according
133
132
  class App
134
133
  include Hobby
135
134
 
136
- get '/' do
137
- # ...
138
- end
139
-
140
- post '/' do
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
135
+ get { 'Some string.' }
136
+ post { 'Some string.' }
137
+ put { 'Some string.' }
138
+ patch { 'Some string.' }
139
+ delete { 'Some string.' }
140
+ # TODO: find a good example for `options`
159
141
  end
160
142
  ----
161
143
 
@@ -344,10 +326,3 @@ To run the specs:
344
326
  ----
345
327
  bundle exec rspec
346
328
  ----
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
@@ -272,5 +272,15 @@ describe Hobby::App do
272
272
  assert { last_response.content_type == 'application/html' }
273
273
  end
274
274
  end
275
+
276
+ describe ScriptName do
277
+ it do
278
+ get '/'
279
+ assert { last_response.body == '' }
280
+
281
+ get '/some/path'
282
+ assert { last_response.body == '/some/path' }
283
+ end
284
+ end
275
285
  end
276
286
  end
@@ -0,0 +1,12 @@
1
+ get do
2
+ script_name
3
+ end
4
+
5
+ app = Class.new do
6
+ include Hobby
7
+ get do
8
+ script_name
9
+ end
10
+ end
11
+
12
+ map '/some/path', app.new
data/spec/helper.rb CHANGED
@@ -1,38 +1,10 @@
1
- require 'devtools/spec_helper'
2
-
3
1
  require 'hobby'
2
+ require_relative 'mutant_patches' if defined? Mutant
4
3
 
5
4
  require 'minitest'
6
5
  require 'minitest-power_assert'
7
6
  Minitest::Assertions.prepend Minitest::PowerAssert::Assertions
8
7
 
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
8
  module EnvFor
37
9
  def env_for path, verb = 'GET'
38
10
  {'REQUEST_METHOD' => verb, 'PATH_INFO' => path }
@@ -0,0 +1,27 @@
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
@@ -18,7 +18,7 @@ module RouterMatchers
18
18
  route && (route.to_proc.call == SOME_ROUTE.call) && params_are_ok
19
19
  end
20
20
 
21
- chain :and_set_params do |**params|
21
+ chain :and_set_params do |params|
22
22
  @params = params
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-20 00:00:00.000000000 Z
11
+ date: 2021-03-27 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: '0'
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: '0'
26
+ version: '2'
27
27
  description:
28
28
  email:
29
29
  - chertoly@gmail.com
@@ -53,6 +53,7 @@ files:
53
53
  - spec/apps/MapInsideInitialize.rb
54
54
  - spec/apps/Nested.rb
55
55
  - spec/apps/OneRouteRouter.rb
56
+ - spec/apps/ScriptName.rb
56
57
  - spec/apps/Status.rb
57
58
  - spec/apps/UnshareableRouterMaps.rb
58
59
  - spec/apps/UnshareableRouterUses.rb
@@ -60,6 +61,7 @@ files:
60
61
  - spec/apps/UseInsideInitialize.rb
61
62
  - spec/apps/WithoutPath.rb
62
63
  - spec/helper.rb
64
+ - spec/mutant_patches.rb
63
65
  - spec/router_matchers.rb
64
66
  - spec/router_spec.rb
65
67
  homepage: https://github.com/ch1c0t/hobby
@@ -74,18 +76,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
76
  requirements:
75
77
  - - ">="
76
78
  - !ruby/object:Gem::Version
77
- version: '0'
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
- rubyforge_project:
85
- rubygems_version: 2.6.13
86
+ rubygems_version: 3.2.3
86
87
  signing_key:
87
88
  specification_version: 4
88
- summary: A minimal DSL over rack
89
+ summary: A professional way to create Rack applications.
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
@@ -104,5 +106,6 @@ test_files:
104
106
  - spec/apps/UseInsideInitialize.rb
105
107
  - spec/apps/WithoutPath.rb
106
108
  - spec/helper.rb
109
+ - spec/mutant_patches.rb
107
110
  - spec/router_matchers.rb
108
111
  - spec/router_spec.rb