hanami-controller 0.8.0 → 0.8.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
2
  SHA1:
3
- metadata.gz: f54bdf6d87a22221ce3dae2d7c17ceb8b8097fcc
4
- data.tar.gz: 1a7108c3fcb857a3a6f5a84055f25afb144b65af
3
+ metadata.gz: 94316cf20a120464d9314f31c0ea0774d8256847
4
+ data.tar.gz: 0d468b04cc1ae458ee3d2cb1188adfae48e63402
5
5
  SHA512:
6
- metadata.gz: 41cebc4b699df51ee187a0423ae9b062299cc374f24e0511defe3ec869aab0833b04044e10aacb0b7b96ff9416b7e975e99576b1d8afd4cef535f7047d5e2f4a
7
- data.tar.gz: d852c7b7c2a3de1f9fdeb2b6a21d034bed9d61efdb0e1187a38e16a2addba194a40094c31f578d0674b6b1dd30a194b2c7e33e2ffd24fa45a58e8349de4c0675
6
+ metadata.gz: 68a1d9c7ae87c693fa7a9ac85ae15b0736bdd1de6dc02f21a9ef320a08f6f1f9b0fc3e99b88a92186c7e1ebc5ebf48cb52b914a400f655c1699b12bdb8bbe61b
7
+ data.tar.gz: b49bfaff6ee7d1150f1f1e99ea335948300d519c8522b200dc0b914ddc7a0d3f7ee9c9778fdc79abfa267998987aa65216f9f2488e09db2b9c1321bb5fc2b69b
@@ -1,6 +1,11 @@
1
1
  # Hanami::Controller
2
2
  Complete, fast and testable actions for Rack
3
3
 
4
+ ## v0.8.1 - 2016-12-19
5
+ ### Fixed
6
+ - [Thorbjørn Hermansen] Don't pollute Rack env's `rack.exception` key if an exception is handled
7
+ - [Luca Guidi] Add `flash` to the default exposures
8
+
4
9
  ## v0.8.0 - 2016-11-15
5
10
  ### Added
6
11
  - [Marion Duprey] Allow `BaseParams#get` to read (nested) arrays
data/README.md CHANGED
@@ -60,7 +60,7 @@ class Show
60
60
  include Hanami::Action
61
61
 
62
62
  def call(params)
63
- @article = ArticleRepository.find params[:id]
63
+ @article = ArticleRepository.new.find(params[:id])
64
64
  end
65
65
  end
66
66
  ```
@@ -82,16 +82,16 @@ Imagine how **fast** the unit test could be.
82
82
  class Show
83
83
  include Hanami::Action
84
84
 
85
- def initialize(repository = ArticleRepository)
85
+ def initialize(repository = ArticleRepository.new)
86
86
  @repository = repository
87
87
  end
88
88
 
89
89
  def call(params)
90
- @article = @repository.find params[:id]
90
+ @article = @repository.find(params[:id])
91
91
  end
92
92
  end
93
93
 
94
- action = Show.new(MemoryArticleRepository)
94
+ action = Show.new(MemoryArticleRepository.new)
95
95
  action.call({ id: 23 })
96
96
  ```
97
97
 
@@ -314,7 +314,7 @@ class Show
314
314
 
315
315
  # `params` in the method signature is optional
316
316
  def set_article(params)
317
- @article = ArticleRepository.find params[:id]
317
+ @article = ArticleRepository.new.find(params[:id])
318
318
  end
319
319
  end
320
320
  ```
@@ -326,7 +326,7 @@ class Show
326
326
  include Hanami::Action
327
327
 
328
328
  before { ... } # do some authentication stuff
329
- before { |params| @article = ArticleRepository.find params[:id] }
329
+ before { |params| @article = ArticleRepository.new.find(params[:id]) }
330
330
 
331
331
  def call(params)
332
332
  end
@@ -358,7 +358,7 @@ class Show
358
358
  handle_exception RecordNotFound => 404
359
359
 
360
360
  def call(params)
361
- @article = ArticleRepository.find params[:id]
361
+ @article = ArticleRepository.new.find(params[:id])
362
362
  end
363
363
  end
364
364
 
@@ -399,7 +399,7 @@ class Show
399
399
  include Hanami::Action
400
400
 
401
401
  def call(params)
402
- @article = ArticleRepository.find params[:id]
402
+ @article = ArticleRepository.new.find(params[:id])
403
403
  end
404
404
  end
405
405
 
@@ -425,7 +425,7 @@ module Articles
425
425
  end
426
426
 
427
427
  def call(params)
428
- @article = ArticleRepository.find params[:id]
428
+ @article = ArticleRepository.new.find(params[:id])
429
429
  end
430
430
  end
431
431
  end
@@ -510,7 +510,7 @@ class Show
510
510
  include Hanami::Action
511
511
 
512
512
  def call(params)
513
- DroidRepository.find(params[:id]) or not_found
513
+ DroidRepository.new.find(params[:id]) or not_found
514
514
  end
515
515
 
516
516
  private
@@ -993,10 +993,10 @@ The following examples are valid constructors:
993
993
  def initialize
994
994
  end
995
995
 
996
- def initialize(repository = ArticleRepository)
996
+ def initialize(repository = ArticleRepository.new)
997
997
  end
998
998
 
999
- def initialize(repository: ArticleRepository)
999
+ def initialize(repository: ArticleRepository.new)
1000
1000
  end
1001
1001
 
1002
1002
  def initialize(options = {})
@@ -26,7 +26,7 @@ module Hanami
26
26
  # @api private
27
27
  def self.included(action)
28
28
  action.class_eval do
29
- _expose :session
29
+ _expose :session, :flash
30
30
  end
31
31
  end
32
32
 
@@ -192,16 +192,7 @@ module Hanami
192
192
  #
193
193
  # @see Hanami::Controller::Configuration#handle_exception
194
194
  def exception_handler(exception)
195
- handler = nil
196
-
197
- @handled_exceptions.each do |exception_class, h|
198
- if exception.kind_of?(exception_class)
199
- handler = h
200
- break
201
- end
202
- end
203
-
204
- handler || DEFAULT_ERROR_CODE
195
+ exception_handler_for(exception) || DEFAULT_ERROR_CODE
205
196
  end
206
197
 
207
198
  # Check if the given exception is handled.
@@ -214,7 +205,23 @@ module Hanami
214
205
  # @see Hanami::Controller::Configuration#handle_exception
215
206
  def handled_exception?(exception)
216
207
  handled_exceptions &&
217
- !!@handled_exceptions.fetch(exception.class) { false }
208
+ !exception_handler_for(exception).nil?
209
+ end
210
+
211
+ # Finds configured handler for given exception, or nil if not found.
212
+ #
213
+ # @param exception [Exception] an exception
214
+ #
215
+ # @since x.x.x
216
+ # @api private
217
+ #
218
+ # @see Hanami::Controller::Configuration#handle_exception
219
+ def exception_handler_for(exception)
220
+ @handled_exceptions.each do |exception_class, handler|
221
+ return handler if exception.kind_of?(exception_class)
222
+ end
223
+
224
+ nil
218
225
  end
219
226
 
220
227
  # Specify which is the default action module to be included when we use
@@ -318,7 +325,7 @@ module Hanami
318
325
  #
319
326
  # Hanami::Controller.configure do
320
327
  # prepare do
321
- # include Hanami::Action::Sessions
328
+ # include Hanami::Action::Session
322
329
  # include MyAuthentication
323
330
  # use SomeMiddleWare
324
331
  #
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '0.8.0'.freeze
6
+ VERSION = '0.8.1'.freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-15 00:00:00.000000000 Z
13
+ date: 2016-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.6.4
157
+ rubygems_version: 2.6.8
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Complete, fast and testable actions for Rack and Hanami