Skip to content

Commit

Permalink
Prepare for v0.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Sep 18, 2015
1 parent dbd2c8c commit 95a90cd
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 14 deletions.
8 changes: 8 additions & 0 deletions 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).
Expand Down
70 changes: 61 additions & 9 deletions README.md
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion lib/lotus/action/cookie_jar.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/lotus/controller/version.rb
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lotus-controller.gemspec
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/version_test.rb
Expand Up @@ -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

0 comments on commit 95a90cd

Please sign in to comment.