cumulus_csv 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,13 @@ That will work for your standard multi part form. The key the file is stored und
29
29
 
30
30
  in that block, you can load each row into your database, or send an email based on each one, whatever it is you're trying to accomplish by having your app interact with this data file.
31
31
 
32
+ you can also now retrieve the whole file as a readable temporary file (if, for example, you were using an excel file instead which couldn't be processed by the CSV reader). To do this:
33
+
34
+ file = manager.fetch_file(key)
35
+ data = file.read
36
+
37
+ for the time being this just streams the remote file to a temp file in place, which will naturally be removed by the next deployment of your app.
38
+
32
39
  == Note on Patches/Pull Requests
33
40
 
34
41
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.1.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cumulus_csv}
8
- s.version = "0.0.3"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["evizitei"]
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/cumulus_csv.rb",
32
32
  "lib/cumulus_csv/data_file_manager.rb",
33
33
  "test/helper.rb",
34
+ "test/some_name.csv",
34
35
  "test/test_data_file_manager.rb"
35
36
  ]
36
37
  s.homepage = %q{http://github.com/evizitei/cumulus_csv}
@@ -34,6 +34,16 @@ module Cumulus
34
34
  return name
35
35
  end
36
36
 
37
+ def fetch_file(file_name)
38
+ File.open(file_name,'w') do |file|
39
+ AWS::S3::S3Object.stream(file_name, BUCKET_NAME) do |chunk|
40
+ file.write chunk
41
+ end
42
+ end
43
+
44
+ return File.open(file_name,'r')
45
+ end
46
+
37
47
  def each_row_of(file_name)
38
48
  data = AWS::S3::S3Object.value(file_name,BUCKET_NAME)
39
49
  ::CSV::Reader.parse(data).each{|row| yield row }
@@ -0,0 +1,3 @@
1
+ 1,2,3
2
+ A,B,C
3
+ x,y,z
@@ -47,20 +47,49 @@ class TestDataFileManager < Test::Unit::TestCase
47
47
  end
48
48
  end
49
49
 
50
- context "Stored csv file" do
51
- should "be iterated over row by row" do
50
+ context "Stored csv file" do
51
+ setup do
52
52
  AWS::S3::S3Object.expects(:value).with("some_name.csv",BUCKET_NAME).returns("1,2,3\nA,B,C\nx,y,z\n")
53
- manager = DataFileManager.new(@auth_hash)
53
+ @manager = DataFileManager.new(@auth_hash)
54
+ end
55
+
56
+ should "be iterated over row by row" do
54
57
  results = []
55
- manager.each_row_of("some_name.csv") do |row|
58
+ @manager.each_row_of("some_name.csv") do |row|
56
59
  results << row
57
60
  end
58
61
  assert_equal ["1","2","3"],results.first
59
62
  assert_equal ["x","y","z"],results.last
63
+ end
64
+ end
65
+
66
+ context "retrieved csv file" do
67
+ setup do
68
+ class << AWS::S3::S3Object
69
+ def stream(file_name, bucket_name)
70
+ yield "1,2,3\nA,B,C\nx,y,z\n"
71
+ end
72
+ end
73
+ @file = DataFileManager.new(@auth_hash).fetch_file("some_name.csv")
74
+ end
75
+
76
+ should "be able to be retrieved as a file" do
77
+ assert_equal "1,2,3\nA,B,C\nx,y,z\n",@file.read
78
+ end
79
+
80
+ should "be able to close when finished" do
81
+ assert_nothing_raised do
82
+ @file.close
83
+ end
84
+ end
85
+
86
+ should "have same name as fetched file" do
87
+ assert_equal "some_name.csv",@file.path
60
88
  end
61
89
  end
62
90
 
63
- end
91
+ end
92
+
64
93
  def nueter_aws!
65
94
  AWS::S3::Base.stubs(:establish_connection!)
66
95
  AWS::S3::Bucket.stubs(:find)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 3
9
- version: 0.0.3
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - evizitei
@@ -82,6 +82,7 @@ files:
82
82
  - lib/cumulus_csv.rb
83
83
  - lib/cumulus_csv/data_file_manager.rb
84
84
  - test/helper.rb
85
+ - test/some_name.csv
85
86
  - test/test_data_file_manager.rb
86
87
  has_rdoc: true
87
88
  homepage: http://github.com/evizitei/cumulus_csv