charcoal 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/charcoal/cross_origin_controller.rb +12 -16
- data/lib/charcoal/version.rb +1 -1
- metadata +107 -13
- data/LICENSE +0 -20
- data/README.md +0 -126
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7622da23541be07303b649835824b230e39533a
|
4
|
+
data.tar.gz: d483edf4d2f4a76e590cdd7c5e0fb71dd3b809fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12e4efbd993a3ca883123a61266d9e726a3516f48451dc589177f3a3b41dcbd54eb5230cdb9424043f0f48660c0a2e4179b29dd352472fbc90c373f4af1bc279
|
7
|
+
data.tar.gz: b136b61fad42a87a3b391529eadf38b328a2f54adc1df2a1386f39f9a07d323a75dbc6459914fdf987eaa2c389ab9ec4c6e5177fcddfc57bd9cd3a4a7ee4a583
|
@@ -50,24 +50,20 @@ class Charcoal::CrossOriginController < ActionController::Base
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def find_route(path, env)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
routes += railties.select {|tie| tie.is_a?(Rails::Engine)}.map(&:routes)
|
59
|
-
|
60
|
-
routes.each do |route_set|
|
61
|
-
begin
|
62
|
-
return route_set.recognize_path(path, env)
|
63
|
-
rescue ActionController::RoutingError
|
64
|
-
end
|
65
|
-
end
|
53
|
+
routes = [Rails.application.routes]
|
54
|
+
|
55
|
+
railties = Rails.application.railties
|
56
|
+
railties = railties.respond_to?(:all) ? railties.all : railties._all
|
57
|
+
routes += railties.select {|tie| tie.is_a?(Rails::Engine)}.map(&:routes)
|
66
58
|
|
67
|
-
|
68
|
-
|
69
|
-
|
59
|
+
routes.each do |route_set|
|
60
|
+
begin
|
61
|
+
return route_set.recognize_path(path, env)
|
62
|
+
rescue ActionController::RoutingError
|
63
|
+
end
|
70
64
|
end
|
65
|
+
|
66
|
+
nil
|
71
67
|
rescue ActionController::RoutingError
|
72
68
|
nil
|
73
69
|
end
|
data/lib/charcoal/version.rb
CHANGED
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:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 3.2.21
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
29
|
+
version: 3.2.21
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5'
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
39
|
+
version: 3.2.21
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '5'
|
@@ -46,27 +46,121 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 2.
|
49
|
+
version: 3.2.21
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '5'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rake
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
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
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: bump
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: yard
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.7'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0.7'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: shoulda
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '3.0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '3.0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: shoulda-context
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: mocha
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
53
151
|
description: Helps you support JSONP and CORS in your Rails app
|
54
152
|
email: sdavidovitz@zendesk.com
|
55
153
|
executables: []
|
56
154
|
extensions: []
|
57
|
-
extra_rdoc_files:
|
58
|
-
- LICENSE
|
59
|
-
- README.md
|
155
|
+
extra_rdoc_files: []
|
60
156
|
files:
|
61
|
-
- LICENSE
|
62
|
-
- README.md
|
63
157
|
- lib/charcoal.rb
|
64
158
|
- lib/charcoal/controller_filter.rb
|
65
159
|
- lib/charcoal/cross_origin.rb
|
66
160
|
- lib/charcoal/cross_origin_controller.rb
|
67
161
|
- lib/charcoal/jsonp.rb
|
68
162
|
- lib/charcoal/version.rb
|
69
|
-
homepage: https://github.com/
|
163
|
+
homepage: https://github.com/steved/charcoal
|
70
164
|
licenses:
|
71
165
|
- MIT
|
72
166
|
metadata: {}
|
@@ -86,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
180
|
version: '0'
|
87
181
|
requirements: []
|
88
182
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.5.0
|
90
184
|
signing_key:
|
91
185
|
specification_version: 4
|
92
186
|
summary: Cross-Origin helper for Rails
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Steven Davidovitz
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# charcoal
|
2
|
-
|
3
|
-
JSONP ("JSON with padding") and CORS (Cross-Origin Resource Sharing) filtration for Rails versions 2 and above.
|
4
|
-
|
5
|
-
## Usage
|
6
|
-
|
7
|
-
### JSONP
|
8
|
-
|
9
|
-
Include the module `Charcoal::JSONP` in the controller you'd like to allow JSONP.
|
10
|
-
You may then use `allow_jsonp` class method with the following options:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
# directive is a method (symbol) or block (taking one argument, the controller instance)
|
14
|
-
allow_jsonp method [method2 ...], :if => directive, :unless => directive
|
15
|
-
```
|
16
|
-
|
17
|
-
`:all` is also a valid argument that applies to all methods. The default (with no arguments) is the same as `:all`.
|
18
|
-
|
19
|
-
Requests that come in with a callback parameter (e.g. `http://test.com/users.json?callback=hello`)
|
20
|
-
will have the response body wrapped in that callback and the content type changed to `application/javascript`
|
21
|
-
|
22
|
-
### CORS
|
23
|
-
|
24
|
-
Please familiarize yourself with the [documentation](https://developer.mozilla.org/En/HTTP_access_control) ([wikipedia](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)) before proceeding.
|
25
|
-
|
26
|
-
Include the module `Charcoal::CrossOrigin` in the controller you'd like to allow CORS.
|
27
|
-
`allow_cors` accepts the same arguments as `allow_jsonp`
|
28
|
-
|
29
|
-
Included is a CORS pre-flight controller that must be hooked up to the Rails router:
|
30
|
-
|
31
|
-
Rails 2:
|
32
|
-
```ruby
|
33
|
-
map.connect "*path.:format", :conditions => { :method => :options }, :action => "preflight", :controller => "cross_origin", :namespace => "charcoal/"
|
34
|
-
```
|
35
|
-
|
36
|
-
Rails 3 / 4:
|
37
|
-
```ruby
|
38
|
-
match '*path.:format' => 'charcoal/cross_origin#preflight', :via => :options
|
39
|
-
```
|
40
|
-
|
41
|
-
#### Configuration
|
42
|
-
|
43
|
-
The configuration options and defaults for CORS are as follows:
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
# Access-Control-Allow-Origin
|
47
|
-
Charcoal.configuration["allow-origin"] # => "*"
|
48
|
-
# Can be set to a string
|
49
|
-
Charcoal.configuration["allow-origin"] = "https://google.com"
|
50
|
-
# Or a block
|
51
|
-
Charcoal.configuration["allow-origin"] = lambda do |controller|
|
52
|
-
controller.request.host
|
53
|
-
end
|
54
|
-
|
55
|
-
# Access-Control-Allow-Headers
|
56
|
-
"allow-headers" => ["X-Requested-With", "X-Prototype-Version"]
|
57
|
-
|
58
|
-
# Sets Access-Control-Allow-Credentials
|
59
|
-
"credentials" => true
|
60
|
-
|
61
|
-
# Access-Control-Allow-Headers
|
62
|
-
"expose-headers" => []
|
63
|
-
|
64
|
-
# Access-Control-Max-Age
|
65
|
-
"max-age" => 86400
|
66
|
-
```
|
67
|
-
|
68
|
-
### Creating Your Own Filter
|
69
|
-
|
70
|
-
It's possible to create your own controller filter like so:
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
require 'charcoal/controller_filter'
|
74
|
-
|
75
|
-
module MyFilter
|
76
|
-
def self.included(klass)
|
77
|
-
klass.extend(ClassMethods)
|
78
|
-
klass.before_filter :quack, :if => :animals_allowed?
|
79
|
-
end
|
80
|
-
|
81
|
-
module ClassMethods
|
82
|
-
include Charcoal::ControllerFilter
|
83
|
-
|
84
|
-
def animals_allowed
|
85
|
-
@animals_allowed ||= Hash.new(lambda {|_| false})
|
86
|
-
end
|
87
|
-
|
88
|
-
allow :animals do |method, directive|
|
89
|
-
animals_allowed[method] = directive
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def animals_allowed?
|
94
|
-
self.class.animals_allowed[params[:action]].call(self)
|
95
|
-
end
|
96
|
-
|
97
|
-
protected
|
98
|
-
|
99
|
-
def quack
|
100
|
-
Rails.logger.info("QUACK!")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
```
|
104
|
-
|
105
|
-
This example adds the `allow_animals` directive that logs "QUACK!" if an applicable request is received.
|
106
|
-
|
107
|
-
## Supported Versions
|
108
|
-
|
109
|
-
Tested with Ruby 1.9.3, 2.0 and 2.1.1 and Rails 2.3, 3.2, 4.0 and 4.1.
|
110
|
-
[![Build Status](https://secure.travis-ci.org/steved555/charcoal.png?branch=master)](http://travis-ci.org/steved555/charcoal)
|
111
|
-
|
112
|
-
## Contributing to charcoal
|
113
|
-
|
114
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
115
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
116
|
-
* Fork the project.
|
117
|
-
* Start a feature/bugfix branch.
|
118
|
-
* Commit and push until you are happy with your contribution.
|
119
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
120
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
121
|
-
|
122
|
-
## Copyright
|
123
|
-
|
124
|
-
Copyright (c) 2012 Steven Davidovitz. See LICENSE for
|
125
|
-
further details.
|
126
|
-
|