hanami-api 0.1.2 → 0.2.0

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
2
  SHA256:
3
- metadata.gz: 671e8eab5f3b562214858055a272e049368bfce7524d639ffa63cd7003bab804
4
- data.tar.gz: 461f4066a630f1a1bd66dbd52f4a977a79a4e09737f5861aeabfcc89d87aee04
3
+ metadata.gz: f2c7e4f7ca1d651ea24fdefb1455358b4c52682c0d1de57658ff7a8fe6253ec4
4
+ data.tar.gz: d900b1c2455f57e16a5f0f2044fcecd1c79f76bec3fc42fbfea13942bfa75dc5
5
5
  SHA512:
6
- metadata.gz: e5398ddac6f97af3898faefd795bbb37f6be9d334163e90e0b68b004eab11e4923b366cc6b44504d06e16b7b67c2b3a3e46ca8a106ee694e65f2f83ab2ab1f41
7
- data.tar.gz: 34ad6218b1001a4b66a4ec9512f320649843928afc98bcd968a347dae0d23df2989ebc46bbd407f93734f934cbd725ded04e8528e9f04e365c180d8748a73097
6
+ metadata.gz: c919a7b1a5f354e99aa2a34cc0189abed167e6bac9b7ba5c96da0329473b08fbfa8e0ac31913462443d874dcd99cad99db6fddf1fb9acd16254964851c0b065f
7
+ data.tar.gz: 160ecda952bb09ccf58f7d205f5626c80811ec3bad13e092d60d9fae64c71983b3b2121bf3c2f52eadb558d19b691269fad0e00b0cd80229e7c83128998033f1
@@ -22,6 +22,7 @@ jobs:
22
22
  fail-fast: false
23
23
  matrix:
24
24
  ruby:
25
+ - "3.0"
25
26
  - "2.7"
26
27
  env:
27
28
  CODACY_RUN_LOCAL: true
@@ -1,6 +1,11 @@
1
1
  # Hanami::API
2
2
  Minimal, extremely fast, lightweight Ruby framework for HTTP APIs.
3
3
 
4
+ ## v0.2.0 - 2021-01-05
5
+ ### Added
6
+ - [Luca Guidi] Official support for Ruby: MRI 3.0
7
+ - [Luca Guidi] Introduce `Hanami::API::DSL` which gives the ability to other Ruby web frameworks to use the `Hanami::API` DSL
8
+
4
9
  ## v0.1.2 - 2020-10-21
5
10
  ### Fixed
6
11
  - [Luca Guidi] Ensure to be able to instantiate an `Hanami::API` app multiple times
data/README.md CHANGED
@@ -145,6 +145,7 @@ get "/", to: MyEndpoint.new
145
145
  * `post`
146
146
  * `patch`
147
147
  * `put`
148
+ * `delete`
148
149
  * `options`
149
150
  * `trace`
150
151
  * `link`
@@ -9,21 +9,15 @@ module Hanami
9
9
  require "hanami/api/error"
10
10
  require "hanami/api/router"
11
11
  require "hanami/api/middleware"
12
+ require "hanami/api/dsl"
12
13
 
13
14
  # @since 0.1.0
14
15
  # @api private
15
16
  def self.inherited(app)
16
17
  super
17
18
 
18
- app.class_eval do
19
- @router = Router.new
20
- end
21
- end
22
-
23
- class << self
24
- # @since 0.1.1
25
- # @api private
26
- attr_reader :router
19
+ app.extend(DSL::ClassMethods)
20
+ app.include(DSL::InstanceMethods)
27
21
  end
28
22
 
29
23
  # Defines a named root route (a GET route for "/")
@@ -292,29 +286,6 @@ module Hanami
292
286
  @router.use(middleware, *args, &blk)
293
287
  end
294
288
 
295
- # @since 0.1.0
296
- def initialize(router: self.class.router.dup)
297
- @router = router
298
-
299
- freeze
300
- end
301
-
302
- # @since 0.1.0
303
- def freeze
304
- @app = @router.to_rack_app
305
- @url_helpers = @router.url_helpers
306
- @router.remove_instance_variable(:@url_helpers)
307
- remove_instance_variable(:@router)
308
- @url_helpers.freeze
309
- @app.freeze
310
- super
311
- end
312
-
313
- # @since 0.1.0
314
- def call(env)
315
- @app.call(env)
316
- end
317
-
318
289
  # TODO: verify if needed here on in block context
319
290
  #
320
291
  # @since 0.1.0
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ class API
5
+ # Expose Hanami::API features to third party frameworks that need to expose
6
+ # a routing DSL.
7
+ #
8
+ # @since 0.2.0
9
+ #
10
+ # @example
11
+ # # framework.rb
12
+ # require "hanami/api"
13
+ #
14
+ # module Framework
15
+ # class App
16
+ # def self.inherited(base)
17
+ # super
18
+ # base.extend(Hanami::API::DSL)
19
+ # end
20
+ # end
21
+ # end
22
+ #
23
+ # # app.rb
24
+ # require "framework/app"
25
+ #
26
+ # class MyApp < Framework::App
27
+ # routes do
28
+ # root { "Hello, World!" }
29
+ # end
30
+ # end
31
+ #
32
+ # # config.ru
33
+ # require_relative "./app"
34
+ #
35
+ # run MyApp.new
36
+ module DSL
37
+ # @since 0.2.0
38
+ # @api private
39
+ def self.extended(app)
40
+ super
41
+
42
+ app.extend(ClassMethods)
43
+ app.extend(ClassMethods::Routes)
44
+ app.include(InstanceMethods)
45
+ end
46
+
47
+ # @since 0.2.0
48
+ # @api private
49
+ module ClassMethods
50
+ # @since 0.2.0
51
+ # @api private
52
+ attr_reader :router
53
+
54
+ # @since 0.2.0
55
+ # @api private
56
+ def self.extended(app)
57
+ super
58
+
59
+ app.class_eval do
60
+ @router = Router.new
61
+ end
62
+ end
63
+
64
+ # @since 0.2.0
65
+ # @api private
66
+ module Routes
67
+ # A block to define application routes
68
+ #
69
+ # This is ONLY available for third-party frameworks that use
70
+ # Hanami::API DSL.
71
+ #
72
+ # If you use Hanami::API directly, this method isn't available.
73
+ #
74
+ # @param blk [Proc] the block to define the routes
75
+ #
76
+ # @see Hanami::API::Router
77
+ #
78
+ # @since 0.2.0
79
+ # @api public
80
+ def routes(&blk)
81
+ router.instance_eval(&blk)
82
+ end
83
+ end
84
+ end
85
+
86
+ module InstanceMethods
87
+ # Initialize the app
88
+ #
89
+ # @param router [Hanami::API::Router] the application router
90
+ #
91
+ # @since 0.2.0
92
+ # @api public
93
+ def initialize(router: self.class.router.dup)
94
+ @router = router
95
+
96
+ freeze
97
+ end
98
+
99
+ # @since 0.2.0
100
+ # @api private
101
+ def freeze
102
+ @app = @router.to_rack_app
103
+ @url_helpers = @router.url_helpers
104
+ @router.remove_instance_variable(:@url_helpers)
105
+ remove_instance_variable(:@router)
106
+ @url_helpers.freeze
107
+ @app.freeze
108
+ super
109
+ end
110
+
111
+ # Compatibility with Rack protocol
112
+ #
113
+ # @param env [Hash] a Rack env for the current request
114
+ #
115
+ # @since 0.2.0
116
+ # @api public
117
+ def call(env)
118
+ @app.call(env)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -3,6 +3,6 @@
3
3
  module Hanami
4
4
  class API
5
5
  # @since 0.1.0
6
- VERSION = "0.1.2"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-21 00:00:00.000000000 Z
11
+ date: 2021-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hanami-router
@@ -100,6 +100,7 @@ files:
100
100
  - hanami-api.gemspec
101
101
  - lib/hanami/api.rb
102
102
  - lib/hanami/api/block/context.rb
103
+ - lib/hanami/api/dsl.rb
103
104
  - lib/hanami/api/error.rb
104
105
  - lib/hanami/api/middleware.rb
105
106
  - lib/hanami/api/middleware/app.rb
@@ -129,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  requirements: []
132
- rubygems_version: 3.1.3
133
+ rubygems_version: 3.2.4
133
134
  signing_key:
134
135
  specification_version: 4
135
136
  summary: Hanami API