clowk 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b01072bf359496a3554b9f8d71aa01574ac36e0a3af9d3f8f1b3f70f403d9518
4
- data.tar.gz: f50d5b860acb97711bebaed47f0ba5ab7a3cd9e22e154db84cf2d89a94e207ad
3
+ metadata.gz: 5027a092ba122ab807f5c0340bc30399f7ab85f9ef41bc99c5610b68df6f47f7
4
+ data.tar.gz: 1f0dd44bf7696a1e3cffed45cb4c48edc92db3025007db39c6ea721f119619a8
5
5
  SHA512:
6
- metadata.gz: 286be44c6c4062b813f88d52c2d47c4a60210a847485a00ebad88e3c73fd4e08092704173446ba3ada396f07d46583d1d3ed5062909dae559f032cd119365d79
7
- data.tar.gz: c8cff8c774890c14b70a8e90b16828bbf36184d00979cead290381c314f3e52d10e4d5357ff4841aa635caaf17ae843901b6bb8f449cd4947e22b746e79d8f87
6
+ metadata.gz: 20a10b0715b1695694c51b915490ad852ba43004e9f1ec1b0fbc7af1d192737250234d4342ea1cac3db7ef6a94dc992b17795ee5ab2f0e0fcc6b23e7237a7c27
7
+ data.tar.gz: 124f14e7d6e53e7c904faa98befc85d18e7f1644f02d654a01c037555d589f4085069945435c7c81aaad36db4158b019b8f61faaeb359ac61839b09edf65d7a0
@@ -116,11 +116,18 @@ module Clowk
116
116
 
117
117
  private
118
118
 
119
- # An API-only app has no session middleware, so there is nowhere to redirect
120
- # a browser to and no way to come back. Redirecting there would answer a
121
- # failed API call with a 302 to a sign-in page the caller cannot use.
119
+ # ActionController::API is the reliable signal, and it has to be checked
120
+ # directly. Probing `session` does not work: with no session middleware
121
+ # loaded, `request.session` still returns a Session object that responds to
122
+ # `[]` and reads as nil — writes vanish, but nothing raises. Inferring
123
+ # "there is a session, so this is a browser" from that answered every API
124
+ # call with a 302 to a sign-in page the caller cannot follow.
125
+ def clowk_api_only?
126
+ defined?(ActionController::API) && is_a?(ActionController::API)
127
+ end
128
+
122
129
  def clowk_api_request?
123
- clowk_session_store.nil? || request.format.json?
130
+ clowk_api_only? || clowk_session_store.nil? || request.format.json?
124
131
  end
125
132
 
126
133
  def clowk_handle_unauthenticated
@@ -139,18 +146,24 @@ module Clowk
139
146
  end
140
147
  end
141
148
 
142
- # Probed rather than assumed: accessing `session` without the middleware
143
- # raises, and `respond_to?` is true either way because the method is
144
- # delegated to the request.
149
+ # nil in API-only controllers. Not because `session` raises there — it does
150
+ # not, see clowk_api_only? but because whatever it hands back writes to
151
+ # nowhere, and callers branch on this to decide whether persisting is worth
152
+ # doing at all.
145
153
  def clowk_session_store
146
154
  return @clowk_session_store if defined?(@clowk_session_store)
147
155
 
148
- @clowk_session_store = begin
149
- store = session
150
- store.respond_to?(:[]) ? store : nil
151
- rescue
152
- nil
153
- end
156
+ @clowk_session_store =
157
+ if clowk_api_only?
158
+ nil
159
+ else
160
+ begin
161
+ store = session
162
+ store.respond_to?(:[]) ? store : nil
163
+ rescue
164
+ nil
165
+ end
166
+ end
154
167
  end
155
168
 
156
169
  def clowk_cookie_jar
data/lib/clowk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clowk
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clowk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clowk