rails_stream_file 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: e67f8bf1b1829cc5b7a3d4e9ef5e20477e5377b0
4
+ data.tar.gz: a9a9d0d53404e336939214e914f117650b2b997f
5
+ SHA512:
6
+ metadata.gz: b7584ce3a883ddfaf6d5d84d1cbd5bd8d5d72b049f9a5bac214bb7cea19820e04bbb5645a3b5adbf3216b7e46211b0e61e2735b867be66f253398f70de17380f
7
+ data.tar.gz: 21145a5b678aacd0359aa6335165a8b81ca3d13f766273da23ecedc760873bdd607deae09b0d7e678e5cc946e9635e7fc0c23830bb107ad5fe932a5dbca250db
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rails-stream_file.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Bernardo Farah
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 ADDED
@@ -0,0 +1,43 @@
1
+ # Rails::StreamFile
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'rails_stream_file', git: 'https://github.com/berfarah/rails_stream_file', require: "rails/stream_file"
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ Adds `stream_file` method to rails which takes an enumerator to output a binary file. Example usage below:
18
+
19
+ ```ruby
20
+ require "csv"
21
+ class EnumerableObject
22
+ def each(&block)
23
+ block.call %w(My Headers Go Here).to_csv
24
+ block.call [1, 2, 3, 4].to_csv
25
+ [
26
+ [123, 123, 123, 123],
27
+ [123, 123, 123, 123]
28
+ ].each { |e| block.call(e.to_csv) }
29
+ end
30
+ end
31
+
32
+ class MyController < ActionController::Base
33
+ def show
34
+ stream_file EnumerableObject.new, filename: "example.csv", mimetype: "text/csv"
35
+ end
36
+ end
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bundle` to install dependencies. Then, run `rake rspec` to run the tests.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ module Rails
2
+ # Include this to have a streamable file
3
+ module StreamFile
4
+ VERSION = "0.0.1"
5
+
6
+ private
7
+
8
+ def stream_file(enum, filename: "example.txt",
9
+ mimetype: "text/plain")
10
+ file_headers(filename, mimetype)
11
+ streaming_headers
12
+ response.status = 200
13
+ self.response_body = enum
14
+ end
15
+
16
+ def file_headers(filename, mimetype)
17
+ headers["Content-Type"] = mimetype
18
+ headers["Content-Disposition"] = "attachment; filename=\"#{filename}\""
19
+ headers["Content-Transfer-Encoding"] = "binary"
20
+ headers["Last-Modified"] = Time.now.ctime.to_s
21
+ end
22
+
23
+ def streaming_headers
24
+ headers["X-Accel-Buffering"] = "no"
25
+ headers["Cache-Control"] ||= "no-cache"
26
+ headers.delete("Content-Length")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rails/stream_file"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_stream_file"
8
+ spec.version = Rails::StreamFile::VERSION
9
+ spec.authors = ["Bernardo Farah"]
10
+ spec.email = ["bfarah@walmart.com"]
11
+
12
+ spec.summary = "Add file streaming as a method in ActionController"
13
+ spec.description = "Allows file streaming where files are enumerables"
14
+ spec.homepage = "https://github.com/berfarah/rails_stream_file"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.10"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rspec"
22
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_stream_file
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bernardo Farah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: Allows file streaming where files are enumerables
56
+ email:
57
+ - bfarah@walmart.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - lib/rails/stream_file.rb
70
+ - rails_stream_file.gemspec
71
+ homepage: https://github.com/berfarah/rails_stream_file
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.5
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Add file streaming as a method in ActionController
94
+ test_files: []
95
+ has_rdoc: