optionsful 0.1.8 → 0.2.3
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.
- data/MIT-LICENSE +1 -1
- data/README.textile +30 -20
- data/Rakefile +1 -1
- data/lib/baurets/optionsful/introspections.rb +11 -18
- data/lib/baurets/optionsful/server.rb +5 -0
- data/lib/baurets/optionsful/version.rb +2 -2
- data/lib/optionsful.rb +0 -1
- data/lib/tasks/optionsful.rake +8 -4
- data/rails/init.rb +7 -1
- data/samples/optionsful.yml +14 -0
- data/spec/optionsful_config_spec.rb +8 -12
- data/spec/optionsful_server_spec.rb +236 -70
- data/spec/spec_helper.rb +7 -22
- metadata +10 -31
- data/lib/baurets/optionsful/documentator.rb +0 -158
- data/spec/optionsful_documentator_spec.rb +0 -117
- data/spec/samples/app/controllers/comments_controller.rb +0 -86
- data/spec/samples/app/controllers/notes_controller.rb +0 -6
- data/spec/samples/app/controllers/posts_controller.rb +0 -185
- data/spec/samples/app/controllers/teams_controller.rb +0 -33
- data/spec/samples/app/controllers/trips_controller.rb +0 -82
data/MIT-LICENSE
CHANGED
@@ -12,4 +12,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
12
12
|
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
13
13
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
14
14
|
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
15
|
-
DEALINGS IN THE SOFTWARE.
|
15
|
+
DEALINGS IN THE SOFTWARE.
|
data/README.textile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
h1.
|
1
|
+
h1. *Optionsful*
|
2
2
|
|
3
|
-
Provide
|
3
|
+
Provide HTTP OPTIONS support for the Ruby on Rails framework.
|
4
4
|
|
5
5
|
* Note for the impatient: installation instructions below.
|
6
6
|
* Note for the dummies: change host names and paths properly.
|
@@ -8,7 +8,7 @@ Provide dynamic information about resources via the OPTIONS' HTTP method on a RE
|
|
8
8
|
|
9
9
|
h2. "-No! No! No! *-Show me the code!*"
|
10
10
|
|
11
|
-
h3.
|
11
|
+
h3. Retrieving an HTTP OPTIONS request via telnet:
|
12
12
|
|
13
13
|
<pre>
|
14
14
|
|
@@ -20,7 +20,7 @@ HTTP/1.1 204 No Content
|
|
20
20
|
Allow: GET, POST
|
21
21
|
Connection: close
|
22
22
|
Date: Thu, 22 Jul 2010 17:20:27 GMT
|
23
|
-
Link: <http://localhost:3000/optionsful/posts>; type=text/html; rel=help
|
23
|
+
Link: "<http://localhost:3000/optionsful/posts>; type=text/html; rel=help"
|
24
24
|
|
25
25
|
OPTIONS /posts/1 HTTP/1.1
|
26
26
|
Host: http://localhost:3000
|
@@ -29,7 +29,7 @@ HTTP/1.1 204 No Content
|
|
29
29
|
Allow: GET, PUT, DELETE
|
30
30
|
Connection: close
|
31
31
|
Date: Thu, 22 Jul 2010 18:14:24 GMT
|
32
|
-
Link: <http://localhost:3000/optionsful/posts/1/>; type=text/html; rel=help
|
32
|
+
Link: "<http://localhost:3000/optionsful/posts/1/>; type=text/html; rel=help"
|
33
33
|
|
34
34
|
OPTIONS /posts/1/comments HTTP/1.1
|
35
35
|
Host: http://localhost:3000
|
@@ -38,19 +38,12 @@ HTTP/1.1 204 No Content
|
|
38
38
|
Allow: GET, POST
|
39
39
|
Connection: close
|
40
40
|
Date: Thu, 22 Jul 2010 18:12:43 GMT
|
41
|
-
Link: <http://localhost:3000/optionsful/posts/1/comments>; type=text/html; rel=help
|
41
|
+
Link: "<http://localhost:3000/optionsful/posts/1/comments>; type=text/html; rel=help"
|
42
42
|
|
43
43
|
</pre>
|
44
44
|
~Note the empty line which is part of the HTTP protocol.~
|
45
45
|
|
46
|
-
h3.
|
47
|
-
|
48
|
-
* Access the given Link header through your preferable browser. Yeah, via an HTTP GET request.
|
49
|
-
* @http://localhost:3000/optionsful/posts/1/comments@ for instance.
|
50
|
-
* Try up adding some RDoc-like comments above your actions definitions on the appropriate controllers.
|
51
|
-
* Refresh the page and your documentation and have fun!
|
52
|
-
* There's a lot of helpful things we can do with this extracted 'on-the-fly' information (metadata).
|
53
|
-
|
46
|
+
h3. Telnet is the geek way. You would like better to use an HTTP client software. I use "HTTP Client":http://ditchnet.org/httpclient/ on Mac OS X.
|
54
47
|
|
55
48
|
h2. INSTALLATION:
|
56
49
|
|
@@ -59,21 +52,38 @@ h2. INSTALLATION:
|
|
59
52
|
<pre>
|
60
53
|
config.gem "optionsful"
|
61
54
|
</pre>
|
62
|
-
# To install it, run:
|
55
|
+
# To install it, run @rake gems:install@ or:
|
63
56
|
<pre>
|
64
57
|
$ gem install optionsful
|
65
58
|
</pre>
|
66
|
-
#
|
59
|
+
# Enjoy! And give feedback! :)
|
60
|
+
|
61
|
+
h2. Link header WARNING
|
62
|
+
|
63
|
+
To enable the Link URI on your application, check the "Wisdomful":http://github.com/kayaman/wisdomful project!
|
67
64
|
|
68
|
-
|
69
|
-
* -Make the installation easier.-
|
70
|
-
* -Create tests! (Oh no! Psst! Don't tell anyone!)-
|
65
|
+
h3. Link base path (Note: _Work in Progress_)
|
71
66
|
|
67
|
+
* To change the generated URI base path, install and edit the configuration file:
|
68
|
+
** run @rake optionsful:yml@
|
69
|
+
** edit the 'optionsful.yml' file at your application's 'config' folder.
|
70
|
+
* Example:
|
71
|
+
<pre>
|
72
|
+
development:
|
73
|
+
http:
|
74
|
+
base_path: /blopts
|
75
|
+
</pre>
|
76
|
+
|
77
|
+
* Note: @Allow@ and @Link@ are expected headers on a response to an HTTP OPTIONS request. I will think about some features to add more flexibility on the @Link@ generation pretty soon.
|
72
78
|
|
73
79
|
h2. KNOWN ISSUES
|
74
|
-
*
|
80
|
+
* Rails route recognition still need some work
|
75
81
|
* Platform: ruby 1.8.7, rails 2.3.8, rack 1.2.1
|
76
82
|
|
83
|
+
h2. Get involved
|
84
|
+
* Mailing list: http://groups.google.com/group/optionsful
|
85
|
+
* Bug tracker : http://kayaman.lighthouseapp.com/projects/56438-optionsful/overview
|
86
|
+
|
77
87
|
h2. CONTRIBUTORS
|
78
88
|
* Me, myself and I, so far.
|
79
89
|
* You are welcome, do it. ;-)
|
data/Rakefile
CHANGED
@@ -7,11 +7,18 @@ module Baurets
|
|
7
7
|
return true if route[0][index] == value
|
8
8
|
end
|
9
9
|
return false
|
10
|
+
|
10
11
|
end
|
11
12
|
|
13
|
+
|
12
14
|
def self.do_routing_introspection
|
13
15
|
returning Array.new do |routes|
|
14
16
|
route_requirements = nil
|
17
|
+
ActionController::Routing::Routes.named_routes.map.each do |named_route|
|
18
|
+
name = named_route[0].to_s
|
19
|
+
routes << [[name], ["GET", named_route[1].requirements[:action]], {:controller => named_route[1].requirements[:controller], :action => named_route[1].requirements[:action]}]
|
20
|
+
#TODO ANY ?!?
|
21
|
+
end
|
15
22
|
ActionController::Routing::Routes.routes.each do |route|
|
16
23
|
static_path = []
|
17
24
|
route.segments.each do |segment|
|
@@ -42,34 +49,20 @@ module Baurets
|
|
42
49
|
guess
|
43
50
|
end
|
44
51
|
|
45
|
-
def self.discover_controller_name(path)
|
46
|
-
routes = do_routing_introspection
|
47
|
-
guess = guess_route(routes, path)
|
48
|
-
routes.each do |route|
|
49
|
-
if route[0] == guess
|
50
|
-
return route[2][:controller]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
52
|
def self.do_the_matches(routes, route_guess)
|
56
53
|
allow = ""
|
57
54
|
routes.each do |route|
|
58
55
|
if route.first == route_guess
|
59
|
-
allow += route[1][0].to_s.upcase + "|"
|
56
|
+
allow += (route[1][0].to_s.upcase + "|") unless allow.include?(route[1][0].to_s.upcase)
|
60
57
|
end
|
61
58
|
end
|
62
|
-
allow = allow.split("|").join(", ")
|
59
|
+
allow = allow.split("|").join(", ")
|
63
60
|
end
|
64
61
|
|
65
62
|
def self.prepare_request_path(path)
|
66
63
|
path_parts = []
|
67
|
-
|
68
|
-
|
69
|
-
path_parts = path.split("/")
|
70
|
-
else
|
71
|
-
path_parts = path
|
72
|
-
end
|
64
|
+
path = path[0..(path.rindex('.')-1)] if path.include?('.')
|
65
|
+
path_parts = path.split("/")
|
73
66
|
path_parts.delete("")
|
74
67
|
path_parts
|
75
68
|
end
|
@@ -32,6 +32,11 @@ module Baurets
|
|
32
32
|
# do request path investigation
|
33
33
|
path = env["PATH_INFO"]
|
34
34
|
route_guess = ::Baurets::Optionsful::Introspections.guess_route(routes, path)
|
35
|
+
|
36
|
+
puts "\nPATH: \n #{path}\n"
|
37
|
+
puts "\nROUTES: \n #{routes.inspect}\n"
|
38
|
+
puts "\nGUESS: \n #{route_guess.inspect}\n"
|
39
|
+
|
35
40
|
# do the matches:
|
36
41
|
allow = ::Baurets::Optionsful::Introspections.do_the_matches(routes, route_guess)
|
37
42
|
end
|
data/lib/optionsful.rb
CHANGED
data/lib/tasks/optionsful.rake
CHANGED
data/rails/init.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
1
|
# Adding Optionsful to the Rack middleware stack:
|
2
2
|
ActionController::Dispatcher.middleware.use Baurets::Optionsful::Server
|
3
|
-
|
3
|
+
|
4
|
+
puts "Gem.searcher.find('optionsful').full_gem_path = #{Gem.searcher.find('optionsful').full_gem_path}"
|
5
|
+
|
6
|
+
Dir["#{Gem.searcher.find('optionsful').full_gem_path}/**/tasks/*.rake"].each do |ext|
|
7
|
+
puts "Loading: #{ext}"
|
8
|
+
load ext
|
9
|
+
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
|
4
3
|
describe Baurets::Optionsful::Config do
|
5
4
|
|
6
5
|
include Rack::Test::Methods
|
7
6
|
|
8
|
-
|
7
|
+
context "Config carries specific settings" do
|
9
8
|
|
10
|
-
describe "
|
9
|
+
describe "try to find the custom configuration file" do
|
11
10
|
|
12
11
|
it "if the custom configuration file exist, try to load settings from it" do
|
13
12
|
config = Baurets::Optionsful::Config.new( {:file => File.join(File.dirname(__FILE__), 'fixtures', 'optionsful.yml'), :environment => "test" })
|
14
13
|
config.base_path.should == "/test"
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
it "if the custom configuration file exist and is not valid, keep the default settings" do
|
18
17
|
config = Baurets::Optionsful::Config.new( {:file => File.join(File.dirname(__FILE__), 'fixtures', 'optionsful_bug.yml'), :environment => "test" })
|
19
18
|
config.base_path.should == "/optionsful"
|
@@ -23,22 +22,19 @@ describe Baurets::Optionsful::Config do
|
|
23
22
|
config = Baurets::Optionsful::Config.new
|
24
23
|
config.base_path.should == "/optionsful"
|
25
24
|
end
|
26
|
-
|
25
|
+
|
27
26
|
it "if RAILS_ROOT is defined, look for the custom configuration file on its config folder" do
|
28
27
|
Baurets::Optionsful::Config.const_set(:RAILS_ROOT, File.dirname(__FILE__))
|
29
28
|
config = Baurets::Optionsful::Config.new
|
30
29
|
config.base_path.should == "/optionsful"
|
31
30
|
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
it "and does not exist, keep default settings" do
|
33
|
+
config = Baurets::Optionsful::Config.new( {:file => File.join(File.dirname(__FILE__), 'fixtures', 'optionsful_xxx.yml'), :environment => "test" })
|
34
|
+
config.base_path.should == "/optionsful"
|
35
|
+
end
|
36
36
|
|
37
|
-
it "and does not exist, keep default settings" do
|
38
|
-
config = Baurets::Optionsful::Config.new( {:file => File.join(File.dirname(__FILE__), 'fixtures', 'optionsful_xxx.yml'), :environment => "test" })
|
39
|
-
config.base_path.should == "/optionsful"
|
40
37
|
end
|
41
38
|
|
42
39
|
end
|
43
|
-
|
44
40
|
end
|