breath 0.3.1 → 0.3.2

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: f7a68cdfbe3fc69697178c18e1d8f73d62028a2a3d659334daaa06724333f568
4
- data.tar.gz: ad43f74a1fedfaf4c900c5b78f8d99f59098c1a516bb87ab08b19447dcf3a2e3
3
+ metadata.gz: b446e626bff570c9558dae487d91f2ba44ab0fabbfa7fe0638eb087ce49024d7
4
+ data.tar.gz: 601d49d45595acead536bdc6f9d29fa2821b9960f3664c44a6bb324058c87315
5
5
  SHA512:
6
- metadata.gz: df992b967d1f6ec8e5ef6339323c5a42a6b680b4e819b6a7c15eb046971e4c000c4ff9569705fd277dc2201be3711988b6b8ea3c70a2e77b6c2f3e760dfa6886
7
- data.tar.gz: 6e206371189f9c6aea5651daa5fcf75c6341948b7f6ff9ee996314c8a9584f3ebaef87db6bedde7cdaf6960801897d85ca542cc80e675f03d92194a3af5db98a
6
+ metadata.gz: 9c2dff25c5747ddb48469548c8bc0ac7b7ab5e18fd90586097f89f09f50c1648059545fd2c2ea3e8b9c6a780cb5e6f13ac8b30b99e8f1ab62de670c39360f67d
7
+ data.tar.gz: 4fc570dfabf9638035bf55404585143df9e39a23c185b6c7f32ba7f2faa661bd4df51585484d7b7a3e49b6f73b8c4e29d168b24b89b5751e4ce932daa870f22d
data/README.md CHANGED
@@ -168,24 +168,14 @@ class Users::HogeController < Users::ApplicationController
168
168
  ...
169
169
  render status: 201
170
170
  rescue => e
171
- render_409 e
171
+ response_body = { error_code: 100, message: "error" }
172
+
173
+ render_409 response_body
172
174
  end
173
175
  end
174
176
  ```
175
177
  Breath plugin automatically rescues from CSRF token error which is status 422, and Internal Server Error with status code 500.<br/>
176
178
  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
179
 
190
180
  #### Last Work
191
181
  You need to create view side.<br/>
@@ -8,13 +8,12 @@ module Breath
8
8
  rescue_from StandardError, with: :render_500
9
9
  rescue_from ActionController::InvalidAuthenticityToken, with: :render_422
10
10
 
11
-
12
- target_class = to_s.split("::")[-2].singularize.constantize
11
+ target_class = to_s.deconstantize.demodulize.singularize.constantize
13
12
  target_name = target_class.to_s.underscore
14
13
  current_target = "current_#{target_name}"
15
14
 
16
15
  include ActionController::Cookies
17
-
16
+
18
17
  define_method :authenticate! do
19
18
  raise AuthenticationError unless cookies.key?("#{target_name}_id".to_sym)
20
19
  raise AuthenticationError if send(current_target).nil?
@@ -49,40 +48,40 @@ module Breath
49
48
 
50
49
  def render_400(res)
51
50
  Rails.logger.error error_message(res)
52
-
51
+
53
52
  render json: res, status: 400
54
53
  end
55
-
54
+
56
55
  def render_401(res)
57
56
  Rails.logger.error error_message(res)
58
-
57
+
59
58
  render json: res, status: 401
60
59
  end
61
-
60
+
62
61
  def render_404(res)
63
62
  Rails.logger.error error_message(res)
64
-
63
+
65
64
  render json: res, status: 404
66
65
  end
67
-
66
+
68
67
  def render_409(res)
69
68
  Rails.logger.error error_message(res)
70
-
69
+
71
70
  render json: res, status: 409
72
71
  end
73
72
 
74
73
  def render_422(res)
75
74
  Rails.logger.error error_message(res)
76
-
75
+
77
76
  render json: res, status: 422
78
77
  end
79
-
78
+
80
79
  def render_500(res)
81
80
  Rails.logger.error error_message(res)
82
-
81
+
83
82
  render json: res, status: 500
84
83
  end
85
-
84
+
86
85
  def error_message(error)
87
86
  "[ERROR] #{error.to_s}"
88
87
  end
@@ -7,7 +7,7 @@ module Breath
7
7
  class InvalidPassword < StandardError; end
8
8
 
9
9
  included do
10
- target_class = to_s.split("::")[-2].singularize.constantize
10
+ target_class = to_s.deconstantize.demodulize.singularize.constantize
11
11
  target_name = target_class.to_s.underscore
12
12
  current_target = "current_#{target_name}"
13
13
 
@@ -1,3 +1,3 @@
1
1
  module Breath
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/breath.rb CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - testCodeV01
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-27 00:00:00.000000000 Z
11
+ date: 2023-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails