charcoal 2.1.5 → 2.2.0

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: 39523d154ea7e30b2bebab0190db9549e5906d883a1ec627a8c19660fa204fc2
4
- data.tar.gz: 248e3b6e60c1945d6ace5e9dd7c57b38c706f9a0d9fa3b9fc13c94748c06db99
3
+ metadata.gz: 909f8ba9bf0ffdda5f2a0d5f45e07f4deb10d2571c5912150cc23215fe01ab4c
4
+ data.tar.gz: 5b1408731b2c94193a5d3527eb339519f8a0cd1c1673daecd9cbb3d980d934c1
5
5
  SHA512:
6
- metadata.gz: ba01154e073e4824251902474ab42c6cf7f89811e2612fa06eeb935177156db5088df100dd76cf49e68819e6ee21ad704c37840158bd4c8acc0a7141c615cf6e
7
- data.tar.gz: e6d5b1cc4e08f96d22dcac886d79887852c53814145417cb386681b8b01d4f38d8a52e107eecc0361bfd7d14b1509d5c72c238d5002ee1907eec00fed6476ce2
6
+ metadata.gz: 122d3bbdcebf2133f24a8d325207207d5084b0c87e4309f9b767f0ec1f8274ba071fce5b98b5c3607fd18cdbd802e47e7a4e0999d766010667e1ca41b0d0ebfa
7
+ data.tar.gz: 9a44e83eab4bfb324c1d346b6bbfbde48f19e0669330665a23dc09e437a484afeab8f4d3d8d64efaf98ad7c1400bf7ac8dbccbd6796057d624baf73f7b4d8d9c
@@ -3,11 +3,11 @@
3
3
 
4
4
  require 'action_controller'
5
5
  require 'active_support/version'
6
+ require 'charcoal/utilities'
6
7
 
7
8
  class Charcoal::CrossOriginController < ActionController::Base
8
9
  include Charcoal::CrossOrigin
9
-
10
- Routing = defined?(ActionDispatch) ? ActionDispatch::Routing : ActionController::Routing
10
+ include Charcoal::Utilities
11
11
 
12
12
  allow_cors :all
13
13
  if respond_to?(:skip_around_action)
@@ -31,44 +31,6 @@ class Charcoal::CrossOriginController < ActionController::Base
31
31
  private
32
32
 
33
33
  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
34
+ allowed_methods_for?(:cors)
73
35
  end
74
36
  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.5"
2
+ VERSION = "2.2.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.5
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Davidovitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2020-03-30 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: '6.0'
22
+ version: '6.1'
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: '6.0'
32
+ version: '6.1'
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: '6.0'
42
+ version: '6.1'
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: '6.0'
52
+ version: '6.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rake
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +131,7 @@ files:
131
131
  - lib/charcoal/cross_origin.rb
132
132
  - lib/charcoal/cross_origin_controller.rb
133
133
  - lib/charcoal/jsonp.rb
134
+ - lib/charcoal/utilities.rb
134
135
  - lib/charcoal/version.rb
135
136
  homepage: https://github.com/zendesk/charcoal
136
137
  licenses:
@@ -144,15 +145,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
145
  requirements:
145
146
  - - ">="
146
147
  - !ruby/object:Gem::Version
147
- version: '0'
148
+ version: 2.4.0
148
149
  required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  requirements:
150
151
  - - ">="
151
152
  - !ruby/object:Gem::Version
152
153
  version: '0'
153
154
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.7.6
155
+ rubygems_version: 3.1.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Cross-Origin helper for Rails