cuba-sendfile 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0084ae1453a3893ad7604b40124c24a73c248e15
4
+ data.tar.gz: a021a95ccbbfaba97470fa001dc7f70838ed53a8
5
+ SHA512:
6
+ metadata.gz: a58f9109dc76cd561566282708b8866bb5ae47821a92a9ffe69d3ffef00e9104858cff3b4261292d373a96bf38bebd9e53173bf707bdf7c6602ccd9cc08547e4
7
+ data.tar.gz: b8af6b451fde9b6567dbe3e0671f47b3695c1ed6102a3582ca1e18ef14be1e061d6f5f34362a5244529b1473c2be7fc8ebdc0134276025e769b16dd9a817cd5b
data/.gems ADDED
@@ -0,0 +1,3 @@
1
+ cuba -v 3.1.0
2
+ cutest -v 1.2.1
3
+ rack-test -v 0.6.2
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Francesco Rodriguez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ cuba-sendfile
2
+ -------------
3
+
4
+ File sending for Cuba.
5
+
6
+ Usage
7
+ -----
8
+
9
+ ```ruby
10
+ require "cuba"
11
+ require "cuba/send_file"
12
+
13
+ Cuba.plugin(Cuba::SendFile)
14
+
15
+ Cuba.define do
16
+ on root do
17
+ send_file("foo.png")
18
+ end
19
+
20
+ on "/download" do
21
+ disposition = 'attachment; filename="foo.png"'
22
+ send_file("foo.png", "Content-Disposition" => disposition)
23
+ end
24
+ end
25
+ ```
26
+
27
+ Installation
28
+ ------------
29
+
30
+ ```
31
+ $ gem install cuba-sendfile
32
+ ```
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cuba-sendfile"
3
+ s.version = "0.0.1"
4
+ s.summary = "File sending for Cuba"
5
+ s.description = s.summary
6
+ s.authors = ["Francesco Rodríguez"]
7
+ s.email = ["frodsan@me.com"]
8
+ s.homepage = "https://github.com/frodsan/cuba-sendfile"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_dependency "cuba"
14
+ s.add_development_dependency "cutest"
15
+ s.add_development_dependency "rack-test"
16
+ end
@@ -0,0 +1,12 @@
1
+ class Cuba
2
+ module SendFile
3
+ def send_file(path, headers = {})
4
+ file = Rack::File.new(nil, headers)
5
+ file.path = path
6
+
7
+ result = file.serving(env)
8
+
9
+ halt([result[0], result[1], file])
10
+ end
11
+ end
12
+ end
data/test/foo.txt ADDED
@@ -0,0 +1 @@
1
+ Hello World
data/test/send_file.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "cuba/test"
2
+ require_relative "../lib/cuba/send_file"
3
+
4
+ FILE = __dir__ + "/foo.txt"
5
+
6
+ Cuba.plugin(Cuba::SendFile)
7
+
8
+ Cuba.define do
9
+ on root do
10
+ send_file(FILE)
11
+ end
12
+
13
+ on "custom" do
14
+ send_file(FILE, "Content-Disposition" => "disposition")
15
+ end
16
+ end
17
+
18
+ scope do
19
+ test "sends the contents of the file" do
20
+ get "/"
21
+
22
+ assert_equal 200, last_response.status
23
+ assert_equal "Hello World\n", last_response.body
24
+ end
25
+
26
+ test "sets response headers" do
27
+ get "/"
28
+
29
+ assert_equal "text/plain", last_response["Content-Type"]
30
+ assert_equal "Hello World\n".length.to_s, last_response["Content-Length"]
31
+ assert_equal File.mtime(FILE).httpdate, last_response["Last-Modified"]
32
+ end
33
+
34
+ test "sets custom header" do
35
+ get "/custom"
36
+
37
+ assert_equal "disposition", last_response["Content-Disposition"]
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuba-sendfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Rodríguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cuba
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cutest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: File sending for Cuba
56
+ email:
57
+ - frodsan@me.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gems"
63
+ - LICENSE
64
+ - README.md
65
+ - cuba-sendfile.gemspec
66
+ - lib/cuba/send_file.rb
67
+ - test/foo.txt
68
+ - test/send_file.rb
69
+ homepage: https://github.com/frodsan/cuba-sendfile
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.2.0
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: File sending for Cuba
93
+ test_files: []