diff --git a/CHANGELOG.md b/CHANGELOG.md index b685300f..c30f1378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Lotus::Controller Complete, fast and testable actions for Rack +## v0.4.5 - 2015-09-23 +### Added +- [Theo Felippe] Added configuration entries: `#default_request_format` and `default_response_format`. +- [Wellington Santos] Error handling to take account of inherited exceptions. + +### Changed +- [Theo Felippe] Deprecated `#default_format` in favor of: `#default_request_format`. + ## v0.4.4 - 2015-06-23 ### Added - [Luca Guidi] Security protection against Cross Site Request Forgery (CSRF). diff --git a/README.md b/README.md index a4318d72..8b039390 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ A Rack compatible Controller layer for [Lotus](http://lotusrb.org). ## Rubies -__Lotus::Controller__ supports Ruby (MRI) 2+ and Rubinius 2.5.7+. +__Lotus::Controller__ supports Ruby (MRI) 2+ ## Installation @@ -432,6 +432,51 @@ action = Articles::Show.new action.call({id: 'unknown'}) # => raises RecordNotFound ``` +#### Inherited Exceptions + +```ruby +class MyCustomException < StandardError +end + +module Articles + class Index + include Lotus::Action + + handle_exception MyCustomException => :handle_my_exception + + def call(params) + raise MyCustomException + end + + private + + def handle_my_exception + # ... + end + end + + class Show + include Lotus::Action + + handle_exception StandardError => :handle_standard_error + + def call(params) + raise MyCustomException + end + + private + + def handle_standard_error + # ... + end + end +end + +Articles::Index.new.call({}) # => `handle_my_exception` will be invoked +Articles::Show.new.call({}) # => `handle_standard_error` will be invoked, + # because `MyCustomException` inherits from `StandardError` +``` + ### Throwable HTTP statuses When `#halt` is used with a valid HTTP code, it stops the execution and sets the proper status and body for the response: @@ -754,7 +799,7 @@ action = Create.new action.call({ article: { title: 'Hello' }}) # => [301, {'Location' => '/articles/23'}, ''] ``` -### Mime Types +### MIME Types `Lotus::Action` automatically sets the `Content-Type` header, according to the request. @@ -796,7 +841,7 @@ action.call({ 'HTTP_ACCEPT' => 'text/html' }) # Content-Type "application/json" action.format # :json ``` -You can restrict the accepted mime types: +You can restrict the accepted MIME types: ```ruby class Show @@ -814,7 +859,7 @@ end # When called with "application/xml" => 406 ``` -You can check if the requested mime type is accepted by the client. +You can check if the requested MIME type is accepted by the client. ```ruby class Show @@ -841,7 +886,7 @@ class Show end ``` -Lotus::Controller is shipped with an extensive list of the most common mime types. +Lotus::Controller is shipped with an extensive list of the most common MIME types. Also, you can register your own: ```ruby @@ -1002,16 +1047,23 @@ Lotus::Controller.configure do # handle_exception ArgumentError => 404 - # Register a format to mime type mapping - # Argument: hash, key: format symbol, value: mime type string, empty by default + # Register a format to MIME type mapping + # Argument: hash, key: format symbol, value: MIME type string, empty by default # format custom: 'application/custom' - # Define a default format to return in case of HTTP request with `Accept: */*` + # Define a fallback format to detect in case of HTTP request with `Accept: */*` + # If not defined here, it will return Rack's default: `application/octet-stream` + # Argument: symbol, it should be already known. defaults to `nil` + # + default_request_format :html + + # Define a default format to set as `Content-Type` header for response, + # unless otherwise specified. # If not defined here, it will return Rack's default: `application/octet-stream` # Argument: symbol, it should be already known. defaults to `nil` # - default_format :html + default_response_format :html # Define a default charset to return in the `Content-Type` response header # If not defined here, it returns `utf-8` diff --git a/lib/lotus/action/cookie_jar.rb b/lib/lotus/action/cookie_jar.rb index c4f274eb..e24ac18d 100644 --- a/lib/lotus/action/cookie_jar.rb +++ b/lib/lotus/action/cookie_jar.rb @@ -28,7 +28,7 @@ class CookieJar # @api private COOKIE_STRING_KEY = 'rack.request.cookie_string'.freeze - # @since x.x.x + # @since 0.4.5 # @api private COOKIE_SEPARATOR = ';,'.freeze diff --git a/lib/lotus/controller/version.rb b/lib/lotus/controller/version.rb index e24269cc..8de19a0e 100644 --- a/lib/lotus/controller/version.rb +++ b/lib/lotus/controller/version.rb @@ -3,6 +3,6 @@ module Controller # Defines the version # # @since 0.1.0 - VERSION = '0.4.4'.freeze + VERSION = '0.4.5'.freeze end end diff --git a/lotus-controller.gemspec b/lotus-controller.gemspec index ca6491de..b961e3df 100644 --- a/lotus-controller.gemspec +++ b/lotus-controller.gemspec @@ -6,8 +6,8 @@ require 'lotus/controller/version' Gem::Specification.new do |spec| spec.name = 'lotus-controller' spec.version = Lotus::Controller::VERSION - spec.authors = ['Luca Guidi', 'Trung Lê'] - spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com'] + spec.authors = ['Luca Guidi', 'Trung Lê', 'Alfonso Uceda'] + spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com', 'uceda73@gmail.com'] spec.description = %q{Complete, fast and testable actions for Rack} spec.summary = %q{Complete, fast and testable actions for Rack and Lotus} spec.homepage = 'http://lotusrb.org' diff --git a/test/version_test.rb b/test/version_test.rb index efbcc177..fa443b16 100644 --- a/test/version_test.rb +++ b/test/version_test.rb @@ -2,6 +2,6 @@ describe Lotus::Controller::VERSION do it 'returns the current version' do - Lotus::Controller::VERSION.must_equal '0.4.4' + Lotus::Controller::VERSION.must_equal '0.4.5' end end