breath 0.2.1 → 0.3.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
  SHA256:
3
- metadata.gz: 76b40953cb6e71c98a7870cc2a90360ff11e7dbfeeacb38ba02ec212ac8995d3
4
- data.tar.gz: 7324b79742b9329015d3e527a6ed5c0abe5402e999933626fb912c2b004e017f
3
+ metadata.gz: f7a68cdfbe3fc69697178c18e1d8f73d62028a2a3d659334daaa06724333f568
4
+ data.tar.gz: ad43f74a1fedfaf4c900c5b78f8d99f59098c1a516bb87ab08b19447dcf3a2e3
5
5
  SHA512:
6
- metadata.gz: f9c1a788f8de0f6765fc943e721f6d468fc44a57174951c5b0a4e02b9fe93971bd194d835e407dcbc8dac905997a88b1bf22fbb8d6166cd8580ddba857b3af87
7
- data.tar.gz: 53d89f967a23d992c47d9692f7c8cd9270a1f51422f9bfaf6b17b8a2d11d2cd53ba76eadc525ffd54d8b257e957910a3b089c913f1605dc2331e410dade80743
6
+ metadata.gz: df992b967d1f6ec8e5ef6339323c5a42a6b680b4e819b6a7c15eb046971e4c000c4ff9569705fd277dc2201be3711988b6b8ea3c70a2e77b6c2f3e760dfa6886
7
+ data.tar.gz: 6e206371189f9c6aea5651daa5fcf75c6341948b7f6ff9ee996314c8a9584f3ebaef87db6bedde7cdaf6960801897d85ca542cc80e675f03d92194a3af5db98a
data/README.md CHANGED
@@ -126,6 +126,67 @@ end
126
126
  ```
127
127
  If you don't configure this, cookie is set permanently.
128
128
 
129
+ #### Error
130
+ When an error occurs when trying to log in or authorize, rescue from the error automatically.
131
+ Otherwise, you can also overwrite rescue method like bellow.<br/>
132
+ `app/controllers/users/application_controller.rb`
133
+ ```ruby
134
+ class Users::ApplicationController < ApplicationController
135
+ ...
136
+
137
+ def render_401(e)
138
+ # Write your programs. Here, e is error class.
139
+ # e.g. Rails.logger.error(e.to_s)
140
+
141
+ super({ error: 111, message: "error occur." })
142
+ end
143
+
144
+ ...
145
+ end
146
+ ```
147
+ An argument you pass to super is returned to the client side as JSON value.<br/>
148
+ In addition, breath plugin provides bellow rescue methods.
149
+ ```ruby
150
+ render_400
151
+ render_401 # Unauthorized.
152
+ render_404 # Not Found.
153
+ render_409 # Conflict.
154
+ render_422 # Unprocessable Entity.
155
+ render_500 # Internal Server Error.
156
+ ```
157
+ You can use these rescue methods in controllers like bellow.
158
+ ```ruby
159
+ class Users::HogeController < Users::ApplicationController
160
+ def index
161
+ ...
162
+ render status: 200
163
+ rescue => e
164
+ render_404 e
165
+ end
166
+
167
+ def update
168
+ ...
169
+ render status: 201
170
+ rescue => e
171
+ render_409 e
172
+ end
173
+ end
174
+ ```
175
+ Breath plugin automatically rescues from CSRF token error which is status 422, and Internal Server Error with status code 500.<br/>
176
+ And you can overwrite these rescue methods.
177
+ ```ruby
178
+ class Users::ApplicationController < ApplicationController
179
+ ...
180
+
181
+ def render_500(e)
182
+ ...
183
+ super
184
+ end
185
+
186
+ ...
187
+ end
188
+ ```
189
+
129
190
  #### Last Work
130
191
  You need to create view side.<br/>
131
192
  In view side, you have remaining works.<br/>
@@ -5,6 +5,10 @@ module Breath
5
5
  class AuthenticationError < StandardError; end
6
6
 
7
7
  included do
8
+ rescue_from StandardError, with: :render_500
9
+ rescue_from ActionController::InvalidAuthenticityToken, with: :render_422
10
+
11
+
8
12
  target_class = to_s.split("::")[-2].singularize.constantize
9
13
  target_name = target_class.to_s.underscore
10
14
  current_target = "current_#{target_name}"
@@ -7,8 +7,6 @@ module Breath
7
7
  class InvalidPassword < StandardError; end
8
8
 
9
9
  included do
10
- rescue_from ActionController::InvalidAuthenticityToken, with: :render_422
11
-
12
10
  target_class = to_s.split("::")[-2].singularize.constantize
13
11
  target_name = target_class.to_s.underscore
14
12
  current_target = "current_#{target_name}"
@@ -1,3 +1,3 @@
1
1
  module Breath
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - testCodeV01