charcoal 2.1.3 → 2.4.0

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: 01d24eacee4c04f78986e956f53472167d2d166aab4035ad14fa862e122ae4a6
4
- data.tar.gz: 62ea8f2b4fa8f0079858a314de61a2dd9119705ee8cd0324922a14db61f07499
3
+ metadata.gz: ef2a06d4d75ba9de3fe1fec8cb8f128c89cb9201df3fb54979b9ad9c56aeb443
4
+ data.tar.gz: f1f16e6875234a4d00ccf26103b8cc2aecdbeefb0f5027c58651918939865bd0
5
5
  SHA512:
6
- metadata.gz: 3bcf3421356e12f9eea20f988a2fa8401f9f9bc99622415550fbc2e8bc652e46946ee6ed79ef0b002352ebdf8d85800421747f0de194ac6aad67add83edd5acf
7
- data.tar.gz: a55906cc7348fa3a75de0497efb6c9d6090ff3842883f8d7aede4580248703384d9d8817109c71f8d76890507ae8809af3635e13fa9931b939213012959336c6
6
+ metadata.gz: 2d784702c58f8845400eb5089984a8baf81ab6a9fd08b3b96216f4d9bf05c148156a93eb1e0cfb394c85ea8a8a1c968dc2f96ee397bf5b16940b6023c51062c2
7
+ data.tar.gz: c287591a440aa6907971299d1ffb7ddc9688d57b4f6e08edf7b6176376b1ba54466ad20d6a73abefbcbaa318d5b0dae1065af56cf3beba48a733428ec1cc9cfa
@@ -42,7 +42,7 @@ module Charcoal
42
42
 
43
43
  def set_cors_headers
44
44
  headers["Access-Control-Allow-Origin"] = allowed_origin
45
- headers["Access-Control-Allow-Credentials"] = Charcoal.configuration["credentials"].to_s
45
+ headers["Access-Control-Allow-Credentials"] = "true" if credentials_allowed?
46
46
  headers["Access-Control-Expose-Headers"] = Charcoal.configuration["expose-headers"].join(",")
47
47
  end
48
48
 
@@ -50,5 +50,10 @@ module Charcoal
50
50
  value = Charcoal.configuration["allow-origin"]
51
51
  value.respond_to?(:call) ? value.call(self) : value.to_s
52
52
  end
53
+
54
+ def credentials_allowed?
55
+ value = Charcoal.configuration["credentials"]
56
+ value.respond_to?(:call) ? value.call(self) : value
57
+ end
53
58
  end
54
59
  end
@@ -1,13 +1,16 @@
1
1
  # This controller handles CORS preflight requests
2
2
  # See https://developer.mozilla.org/En/HTTP_access_control for documentation
3
3
 
4
- require 'action_controller'
4
+ require 'action_controller/metal'
5
5
  require 'active_support/version'
6
+ require 'charcoal/utilities'
6
7
 
7
- class Charcoal::CrossOriginController < ActionController::Base
8
+ class Charcoal::CrossOriginController < ActionController::Metal
9
+ include AbstractController::Callbacks
10
+ include ActionController::Head
11
+ include ActionController::Instrumentation
8
12
  include Charcoal::CrossOrigin
9
-
10
- Routing = defined?(ActionDispatch) ? ActionDispatch::Routing : ActionController::Routing
13
+ include Charcoal::Utilities
11
14
 
12
15
  allow_cors :all
13
16
  if respond_to?(:skip_around_action)
@@ -31,44 +34,6 @@ class Charcoal::CrossOriginController < ActionController::Base
31
34
  private
32
35
 
33
36
  def allowed_methods
34
- @allowed_methods ||= Routing::HTTP_METHODS.select do |verb|
35
- next if verb == :options
36
-
37
- route = find_route(request.path, request.env.merge(:method => verb))
38
-
39
- if route
40
- controller = route[:controller].camelize
41
- controller = "#{controller}Controller".constantize
42
-
43
- action = route[:action] || params[:path].last.split(".").first
44
-
45
- instance = controller.new
46
- instance.request = request
47
- instance.response = response
48
-
49
- controller.respond_to?(:cors_allowed) && controller.cors_allowed?(instance, action)
50
- else
51
- false
52
- end
53
- end
54
- end
55
-
56
- def find_route(path, env)
57
- routes = [Rails.application.routes]
58
-
59
- railties = Rails.application.railties
60
- railties = railties.respond_to?(:all) ? railties.all : railties._all
61
- routes += railties.select {|tie| tie.is_a?(Rails::Engine)}.map(&:routes)
62
-
63
- routes.each do |route_set|
64
- begin
65
- return route_set.recognize_path(path, env)
66
- rescue ActionController::RoutingError
67
- end
68
- end
69
-
70
- nil
71
- rescue ActionController::RoutingError
72
- nil
37
+ allowed_methods_for?(:cors)
73
38
  end
74
39
  end
@@ -0,0 +1,56 @@
1
+ require 'action_controller'
2
+
3
+ module Charcoal::Utilities
4
+ Routing = defined?(ActionDispatch) ? ActionDispatch::Routing : ActionController::Routing
5
+
6
+ def allowed_methods_for?(protocol)
7
+ @allowed_methods ||= {}
8
+ return @allowed_methods[protocol] if @allowed_methods[protocol]
9
+ @allowed_methods[protocol] = methods_allowed_for?(protocol)
10
+ end
11
+
12
+ private
13
+
14
+ def methods_allowed_for?(protocol)
15
+ Routing::HTTP_METHODS.select do |verb|
16
+ next if verb == :options
17
+
18
+ route = find_route(request.path, request.env.merge(:method => verb))
19
+
20
+ if route
21
+ controller = route[:controller].camelize
22
+ controller = "#{controller}Controller".constantize
23
+
24
+ action = route[:action] || params[:path].last.split(".").first
25
+
26
+ instance = controller.new
27
+ instance.request = request
28
+ instance.response = response
29
+
30
+ method_name = "#{protocol}_allowed"
31
+ controller.respond_to?(method_name.to_sym) && controller.send(method_name + '?', instance, action)
32
+ else
33
+ false
34
+ end
35
+ end
36
+ end
37
+
38
+ def find_route(path, env)
39
+ routes = [Rails.application.routes]
40
+
41
+ railties = Rails.application.railties
42
+ railties = railties.respond_to?(:all) ? railties.all : railties._all
43
+ routes += railties.select {|tie| tie.is_a?(Rails::Engine)}.map(&:routes)
44
+
45
+ routes.each do |route_set|
46
+ begin
47
+ return route_set.recognize_path(path, env)
48
+ rescue ActionController::RoutingError
49
+ end
50
+ end
51
+
52
+ nil
53
+ rescue ActionController::RoutingError
54
+ nil
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module Charcoal
2
- VERSION = "2.1.3"
2
+ VERSION = "2.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charcoal
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Davidovitz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-23 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 3.2.21
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.2'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 3.2.21
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.2'
32
+ version: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: actionpack
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: 3.2.21
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '5.2'
42
+ version: '6.2'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: 3.2.21
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '5.2'
52
+ version: '6.2'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rake
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -64,20 +64,6 @@ dependencies:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
- - !ruby/object:Gem::Dependency
68
- name: wwtd
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: '0'
74
- type: :development
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: '0'
81
67
  - !ruby/object:Gem::Dependency
82
68
  name: bump
83
69
  requirement: !ruby/object:Gem::Requirement
@@ -131,12 +117,13 @@ files:
131
117
  - lib/charcoal/cross_origin.rb
132
118
  - lib/charcoal/cross_origin_controller.rb
133
119
  - lib/charcoal/jsonp.rb
120
+ - lib/charcoal/utilities.rb
134
121
  - lib/charcoal/version.rb
135
122
  homepage: https://github.com/zendesk/charcoal
136
123
  licenses:
137
124
  - MIT
138
125
  metadata: {}
139
- post_install_message:
126
+ post_install_message:
140
127
  rdoc_options: []
141
128
  require_paths:
142
129
  - lib
@@ -144,16 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
131
  requirements:
145
132
  - - ">="
146
133
  - !ruby/object:Gem::Version
147
- version: '0'
134
+ version: '2.5'
148
135
  required_rubygems_version: !ruby/object:Gem::Requirement
149
136
  requirements:
150
137
  - - ">="
151
138
  - !ruby/object:Gem::Version
152
139
  version: '0'
153
140
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.7.4
156
- signing_key:
141
+ rubygems_version: 3.2.2
142
+ signing_key:
157
143
  specification_version: 4
158
144
  summary: Cross-Origin helper for Rails
159
145
  test_files: []