lunetas 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/Rakefile +3 -9
- data/VERSION +1 -1
- data/examples/stand_alone_app/app.rb +12 -0
- data/examples/stand_alone_app/config.ru +3 -0
- data/examples/stand_alone_app/public/lunetas.jpg +0 -0
- data/examples/stand_alone_app/templates/index.erb +12 -0
- data/lib/lunetas.rb +1 -0
- data/lib/lunetas/bag.rb +24 -2
- data/lib/lunetas/candy.rb +2 -0
- data/lib/lunetas/candy/response_handler.rb +7 -14
- data/lib/lunetas/candy/template_parsing.rb +17 -0
- data/lib/lunetas/error.rb +3 -0
- data/spec/lunetas/bag_spec.rb +21 -0
- data/spec/spec_helper.rb +2 -3
- data/spec/support/image.png +1 -0
- metadata +16 -10
- data/.gitignore +0 -24
data/README.md
CHANGED
@@ -25,6 +25,9 @@ running, you just need to add `run Lunetas::Bag` in your config.ru file.
|
|
25
25
|
If you are going to use Lunetas behind a framework like Rails. You just need to add
|
26
26
|
the gem, `require 'lunetas'` in your metal, and you are ready to go.
|
27
27
|
|
28
|
+
Now with support for public assets, and templates. Check out the example under
|
29
|
+
/examples/stand_alone_app, to see how it works!
|
30
|
+
|
28
31
|
Examples
|
29
32
|
--------
|
30
33
|
|
data/Rakefile
CHANGED
@@ -21,16 +21,10 @@ rescue LoadError
|
|
21
21
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
22
|
end
|
23
23
|
|
24
|
-
require '
|
25
|
-
|
26
|
-
spec.
|
27
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
-
end
|
29
|
-
|
30
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
-
spec.libs << 'lib' << 'spec'
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
26
|
+
spec.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
|
32
27
|
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
-
spec.rcov = true
|
34
28
|
end
|
35
29
|
|
36
30
|
task :spec => :check_dependencies
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
Binary file
|
data/lib/lunetas.rb
CHANGED
data/lib/lunetas/bag.rb
CHANGED
@@ -13,6 +13,22 @@ module Lunetas::Bag
|
|
13
13
|
@@candies[regex] = candy
|
14
14
|
end
|
15
15
|
|
16
|
+
# Specifies where the public assets are located.
|
17
|
+
# @param [String] directory where the assets are located.
|
18
|
+
# @raise [Lunetas::Error::NoSuchDirectory] if the directory does not exists.
|
19
|
+
def self.set_public_directory(directory)
|
20
|
+
unless File.directory? File.expand_path(directory)
|
21
|
+
raise Lunetas::Error::NoSuchDirectory
|
22
|
+
end
|
23
|
+
@@public_directory = File.expand_path(directory)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Gets the public directory of assets.
|
27
|
+
# @return [String] the location, if not set public/
|
28
|
+
def self.public_directory
|
29
|
+
@@public_directory ||= File.expand_path("public")
|
30
|
+
end
|
31
|
+
|
16
32
|
# Rack's call method. Will be called with the env, from rack. If it matches
|
17
33
|
# a regular expression, it will start a new instance of the propiertary class.
|
18
34
|
# If there's no matching class, it will return a 404.
|
@@ -21,11 +37,17 @@ module Lunetas::Bag
|
|
21
37
|
# @return [Array] the rack response.
|
22
38
|
def self.call(env)
|
23
39
|
@url_match = nil
|
24
|
-
match_regex = @@candies.keys.find do |regex|
|
40
|
+
match_regex = @@candies.keys.find do |regex|
|
25
41
|
@url_match = env['PATH_INFO'].match(regex)
|
26
42
|
end
|
27
43
|
unless match_regex
|
28
|
-
|
44
|
+
if File.exists? public_directory + env['PATH_INFO']
|
45
|
+
file = public_directory + env['PATH_INFO']
|
46
|
+
content_type = Rack::Mime.mime_type(File.extname(file))
|
47
|
+
return [200, {"Content-Type" => content_type}, [File.read(file)]]
|
48
|
+
else
|
49
|
+
return [404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]]
|
50
|
+
end
|
29
51
|
end
|
30
52
|
candy = @@candies[match_regex].new(env, @url_match.to_a)
|
31
53
|
candy.bite
|
data/lib/lunetas/candy.rb
CHANGED
@@ -16,6 +16,7 @@ module Lunetas::Candy
|
|
16
16
|
autoload :MethodStrategy, base_dir + 'method_strategy.rb'
|
17
17
|
autoload :RequestWrapper, base_dir + 'request_wrapper.rb'
|
18
18
|
autoload :ResponseHandler, base_dir + 'response_handler.rb'
|
19
|
+
autoload :TemplateParsing, base_dir + 'template_parsing.rb'
|
19
20
|
|
20
21
|
# @private
|
21
22
|
def self.included(receiver)
|
@@ -25,5 +26,6 @@ module Lunetas::Candy
|
|
25
26
|
receiver.send :include, RequestWrapper::InstanceMethods
|
26
27
|
receiver.send :include, ResponseHandler::InstanceMethods
|
27
28
|
receiver.send :extend, ResponseHandler::ClassMethods
|
29
|
+
receiver.send :include, TemplateParsing::InstanceMethods
|
28
30
|
end
|
29
31
|
end
|
@@ -7,20 +7,13 @@ module Lunetas::Candy::ResponseHandler
|
|
7
7
|
# @return [Array] a Rack::Request response.
|
8
8
|
def handle_call
|
9
9
|
case @req.request_method
|
10
|
-
when 'GET'
|
11
|
-
|
12
|
-
when '
|
13
|
-
|
14
|
-
when '
|
15
|
-
|
16
|
-
when '
|
17
|
-
delete
|
18
|
-
when 'HEAD'
|
19
|
-
head
|
20
|
-
when 'TRACE'
|
21
|
-
trace
|
22
|
-
when 'OPTIONS'
|
23
|
-
options
|
10
|
+
when 'GET' then get
|
11
|
+
when 'POST' then post
|
12
|
+
when 'PUT' then put
|
13
|
+
when 'DELETE' then delete
|
14
|
+
when 'HEAD' then head
|
15
|
+
when 'TRACE' then trace
|
16
|
+
when 'OPTIONS' then options
|
24
17
|
else
|
25
18
|
response = other_verb(@req.request_method)
|
26
19
|
raise Lunetas::Error::APIError unless response
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Lunetas::Candy::TemplateParsing
|
2
|
+
module InstanceMethods
|
3
|
+
# Parses the given file, located in templates/[template_name].erb.
|
4
|
+
# @param filename the file located in the templates directory.
|
5
|
+
# @return [String] the erb parsed template.
|
6
|
+
def erb(filename)
|
7
|
+
file = File.expand_path("templates/#{filename}.erb")
|
8
|
+
ERB.new(File.read(file)).result(get_binding)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
# @private
|
13
|
+
def get_binding
|
14
|
+
binding
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/lunetas/error.rb
CHANGED
data/spec/lunetas/bag_spec.rb
CHANGED
@@ -36,5 +36,26 @@ describe Lunetas::Bag do
|
|
36
36
|
@luneta_class.should_receive(:new).with(env, ['bacon/bbacon', 'bbacon'])
|
37
37
|
Lunetas::Bag.call(env)
|
38
38
|
end
|
39
|
+
|
40
|
+
it 'should serve an external file' do
|
41
|
+
Lunetas::Bag.set_public_directory "spec/support"
|
42
|
+
env = mock_env('/image.png')
|
43
|
+
response = [200, {"Content-Type" => "image/png"}, ["test\n"]]
|
44
|
+
Lunetas::Bag.call(env).should == response
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'set_public_directory' do
|
49
|
+
it 'should raise an exception if the directory is not found' do
|
50
|
+
lambda {
|
51
|
+
Lunetas::Bag.set_public_directory "blah"
|
52
|
+
}.should raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should change the value if the directory is found' do
|
56
|
+
lambda {
|
57
|
+
Lunetas::Bag.set_public_directory "examples"
|
58
|
+
}.should change(Lunetas::Bag, :public_directory)
|
59
|
+
end
|
39
60
|
end
|
40
61
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'lunetas'
|
4
|
-
require '
|
5
|
-
require 'spec/autorun'
|
4
|
+
require 'rspec'
|
6
5
|
|
7
|
-
|
6
|
+
RSpec.configure do |config|
|
8
7
|
|
9
8
|
end
|
10
9
|
|
@@ -0,0 +1 @@
|
|
1
|
+
test
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lunetas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Iv\xC3\xA1n Vald\xC3\xA9s (@ivanvc)"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-02 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -87,7 +87,6 @@ extra_rdoc_files:
|
|
87
87
|
- README.md
|
88
88
|
files:
|
89
89
|
- .document
|
90
|
-
- .gitignore
|
91
90
|
- LICENSE
|
92
91
|
- README.md
|
93
92
|
- Rakefile
|
@@ -96,6 +95,10 @@ files:
|
|
96
95
|
- examples/content_types.rb
|
97
96
|
- examples/jay_son.rb
|
98
97
|
- examples/redirect.rb
|
98
|
+
- examples/stand_alone_app/app.rb
|
99
|
+
- examples/stand_alone_app/config.ru
|
100
|
+
- examples/stand_alone_app/public/lunetas.jpg
|
101
|
+
- examples/stand_alone_app/templates/index.erb
|
99
102
|
- examples/testing.rb
|
100
103
|
- lib/lunetas.rb
|
101
104
|
- lib/lunetas/bag.rb
|
@@ -104,18 +107,20 @@ files:
|
|
104
107
|
- lib/lunetas/candy/method_strategy.rb
|
105
108
|
- lib/lunetas/candy/request_wrapper.rb
|
106
109
|
- lib/lunetas/candy/response_handler.rb
|
110
|
+
- lib/lunetas/candy/template_parsing.rb
|
107
111
|
- lib/lunetas/error.rb
|
108
112
|
- spec/lunetas/bag_spec.rb
|
109
113
|
- spec/lunetas/candy_spec.rb
|
110
114
|
- spec/spec.opts
|
111
115
|
- spec/spec_helper.rb
|
116
|
+
- spec/support/image.png
|
112
117
|
has_rdoc: true
|
113
118
|
homepage: http://github.com/ivanvc/lunetas
|
114
119
|
licenses: []
|
115
120
|
|
116
121
|
post_install_message:
|
117
|
-
rdoc_options:
|
118
|
-
|
122
|
+
rdoc_options: []
|
123
|
+
|
119
124
|
require_paths:
|
120
125
|
- lib
|
121
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -144,10 +149,11 @@ signing_key:
|
|
144
149
|
specification_version: 3
|
145
150
|
summary: Rack micro framework intended for APIs
|
146
151
|
test_files:
|
147
|
-
- spec/lunetas/bag_spec.rb
|
148
|
-
- spec/lunetas/candy_spec.rb
|
149
|
-
- spec/spec_helper.rb
|
150
152
|
- examples/content_types.rb
|
151
153
|
- examples/jay_son.rb
|
152
154
|
- examples/redirect.rb
|
155
|
+
- examples/stand_alone_app/app.rb
|
153
156
|
- examples/testing.rb
|
157
|
+
- spec/lunetas/bag_spec.rb
|
158
|
+
- spec/lunetas/candy_spec.rb
|
159
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED