streamy_csv 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/README.md +1 -1
- data/Rakefile +6 -0
- data/lib/streamy_csv.rb +1 -0
- data/lib/streamy_csv/version.rb +1 -1
- data/spec/streamy_csv_spec.rb +64 -0
- data/streamy_csv.gemspec +3 -1
- metadata +23 -4
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/streamy_csv.rb
CHANGED
data/lib/streamy_csv/version.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module ActionController
|
4
|
+
class Base
|
5
|
+
attr_accessor :response_body
|
6
|
+
|
7
|
+
def headers
|
8
|
+
@headers ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def response
|
12
|
+
@response ||= OpenStruct.new
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
$: << File.join(File.dirname(__FILE__), "/../lib")
|
19
|
+
require 'streamy_csv.rb'
|
20
|
+
require 'csv'
|
21
|
+
|
22
|
+
describe StreamyCsv do
|
23
|
+
|
24
|
+
it 'extends the action controller with the module' do
|
25
|
+
ActionController::Base.ancestors.should include(StreamyCsv)
|
26
|
+
end
|
27
|
+
|
28
|
+
context '#stream_csv' do
|
29
|
+
before(:each) do
|
30
|
+
@controller = ActionController::Base.new
|
31
|
+
@header = CSV::Row.new([:name, :title], ['Name', 'Title'], true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'sets the streaming headers' do
|
35
|
+
@controller.stream_csv('abc.csv', @header)
|
36
|
+
@controller.headers.should include({'X-Accel-Buffering' => 'no',
|
37
|
+
"Cache-Control" => "no-cache"
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sets the file headers' do
|
42
|
+
@controller.stream_csv('abc.csv', @header)
|
43
|
+
@controller.headers.should include({"Content-Type" => "text/csv",
|
44
|
+
"Content-disposition" => "attachment; filename=\"abc.csv\""
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'streams the csv file' do
|
49
|
+
row_1 = CSV::Row.new([:name, :title], ['AB', 'Mr'])
|
50
|
+
row_2 = CSV::Row.new([:name, :title], ['CD', 'Pres'])
|
51
|
+
|
52
|
+
rows = [@header, row_1]
|
53
|
+
|
54
|
+
@controller.stream_csv('abc.csv', @header) do |rows|
|
55
|
+
rows << row_1
|
56
|
+
rows << row_2
|
57
|
+
end
|
58
|
+
|
59
|
+
@controller.response.status.should == 200
|
60
|
+
@controller.response_body.is_a?(Enumerator).should == true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/streamy_csv.gemspec
CHANGED
@@ -10,10 +10,12 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["sohan39@gmail.com"]
|
11
11
|
gem.description = %q{Streamy CSV lets you stream live generated CSV files}
|
12
12
|
gem.summary = %q{Provides a simple API for your controllers to stream CSV files one row at a time}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/smsohan/streamy_csv"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('rspec')
|
19
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streamy_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,23 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-05-10 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Streamy CSV lets you stream live generated CSV files
|
15
31
|
email:
|
16
32
|
- sohan39@gmail.com
|
@@ -19,14 +35,16 @@ extensions: []
|
|
19
35
|
extra_rdoc_files: []
|
20
36
|
files:
|
21
37
|
- .gitignore
|
38
|
+
- .rspec
|
22
39
|
- Gemfile
|
23
40
|
- LICENSE.txt
|
24
41
|
- README.md
|
25
42
|
- Rakefile
|
26
43
|
- lib/streamy_csv.rb
|
27
44
|
- lib/streamy_csv/version.rb
|
45
|
+
- spec/streamy_csv_spec.rb
|
28
46
|
- streamy_csv.gemspec
|
29
|
-
homepage:
|
47
|
+
homepage: https://github.com/smsohan/streamy_csv
|
30
48
|
licenses: []
|
31
49
|
post_install_message:
|
32
50
|
rdoc_options: []
|
@@ -51,4 +69,5 @@ signing_key:
|
|
51
69
|
specification_version: 3
|
52
70
|
summary: Provides a simple API for your controllers to stream CSV files one row at
|
53
71
|
a time
|
54
|
-
test_files:
|
72
|
+
test_files:
|
73
|
+
- spec/streamy_csv_spec.rb
|