remote_table 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/remote_table.rb +17 -10
- data/lib/remote_table/format.rb +0 -4
- data/lib/remote_table/format/delimited.rb +1 -1
- data/lib/remote_table/format/fixed_width.rb +1 -1
- data/lib/remote_table/format/html.rb +1 -1
- data/lib/remote_table/format/mixins/rooable.rb +2 -0
- data/lib/remote_table/local_file.rb +16 -2
- data/lib/remote_table/properties.rb +0 -8
- data/lib/remote_table/version.rb +1 -1
- data/test/test_remote_table.rb +16 -0
- metadata +4 -4
data/lib/remote_table.rb
CHANGED
@@ -54,6 +54,13 @@ class RemoteTable
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def each(&blk)
|
57
|
+
to_a.each { |row| yield row }
|
58
|
+
end
|
59
|
+
alias :each_row :each
|
60
|
+
|
61
|
+
def to_a
|
62
|
+
return @to_a if @to_a.is_a? ::Array
|
63
|
+
@to_a = []
|
57
64
|
format.each do |row|
|
58
65
|
row['row_hash'] = ::RemoteTable.hasher.hash row
|
59
66
|
# allow the transformer to return multiple "virtual rows" for every real row
|
@@ -64,26 +71,26 @@ class RemoteTable
|
|
64
71
|
end
|
65
72
|
next if properties.select and !properties.select.call(virtual_row)
|
66
73
|
next if properties.reject and properties.reject.call(virtual_row)
|
67
|
-
|
74
|
+
@to_a.push virtual_row
|
68
75
|
end
|
69
76
|
end
|
77
|
+
@to_a
|
70
78
|
end
|
71
|
-
alias :
|
79
|
+
alias :rows :to_a
|
72
80
|
|
73
81
|
# Get a row by row number
|
74
82
|
def [](row_number)
|
75
83
|
to_a[row_number]
|
76
84
|
end
|
77
85
|
|
78
|
-
#
|
79
|
-
def
|
80
|
-
|
81
|
-
@to_a =
|
82
|
-
|
83
|
-
|
86
|
+
# clear the row cache to save memory
|
87
|
+
def free
|
88
|
+
@to_a.clear if @to_a.is_a?(::Array)
|
89
|
+
@to_a = nil
|
90
|
+
::GC.start
|
91
|
+
nil
|
84
92
|
end
|
85
|
-
|
86
|
-
|
93
|
+
|
87
94
|
# Used internally to execute stuff in shells.
|
88
95
|
def self.executor
|
89
96
|
Executor.instance
|
data/lib/remote_table/format.rb
CHANGED
@@ -2,7 +2,7 @@ require 'fileutils'
|
|
2
2
|
require 'escape'
|
3
3
|
require 'tmpdir'
|
4
4
|
class RemoteTable
|
5
|
-
class LocalFile
|
5
|
+
class LocalFile #:nodoc:all
|
6
6
|
|
7
7
|
attr_reader :t
|
8
8
|
|
@@ -15,11 +15,25 @@ class RemoteTable
|
|
15
15
|
@path
|
16
16
|
end
|
17
17
|
|
18
|
+
def delete
|
19
|
+
::FileUtils.rm_rf staging_dir_path
|
20
|
+
@path = nil
|
21
|
+
@staging_dir_path = nil
|
22
|
+
end
|
23
|
+
|
18
24
|
private
|
19
25
|
|
26
|
+
def staging_dir_path #:nodoc:
|
27
|
+
return @staging_dir_path if @staging_dir_path.is_a?(::String)
|
28
|
+
srand # in case this was forked by resque
|
29
|
+
@staging_dir_path = ::File.join ::Dir.tmpdir, 'remote_table_gem', rand.to_s
|
30
|
+
::FileUtils.mkdir_p @staging_dir_path
|
31
|
+
@staging_dir_path
|
32
|
+
end
|
33
|
+
|
20
34
|
def save_locally
|
21
35
|
return if @path.is_a?(::String)
|
22
|
-
@path = ::File.join(
|
36
|
+
@path = ::File.join(staging_dir_path, ::File.basename(t.properties.uri.path))
|
23
37
|
download
|
24
38
|
decompress
|
25
39
|
unpack
|
@@ -209,13 +209,5 @@ class RemoteTable
|
|
209
209
|
Format::Delimited
|
210
210
|
end
|
211
211
|
end
|
212
|
-
|
213
|
-
def staging_dir_path #:nodoc:
|
214
|
-
return @staging_dir_path if @staging_dir_path.is_a?(::String)
|
215
|
-
srand # in case this was forked by resque
|
216
|
-
@staging_dir_path = ::File.join ::Dir.tmpdir, 'remote_table_gem', rand.to_s
|
217
|
-
::FileUtils.mkdir_p @staging_dir_path
|
218
|
-
@staging_dir_path
|
219
|
-
end
|
220
212
|
end
|
221
213
|
end
|
data/lib/remote_table/version.rb
CHANGED
data/test/test_remote_table.rb
CHANGED
@@ -43,4 +43,20 @@ class TestRemoteTable < Test::Unit::TestCase
|
|
43
43
|
:select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] }
|
44
44
|
assert_equal '9.09%', t[0]['LDGV']
|
45
45
|
end
|
46
|
+
|
47
|
+
should 'not blow up if each is called twice' do
|
48
|
+
t = RemoteTable.new 'http://spreadsheets.google.com/pub?key=tObVAGyqOkCBtGid0tJUZrw'
|
49
|
+
assert_nothing_raised do
|
50
|
+
t.each { |row| }
|
51
|
+
t.each { |row| }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'allow itself to be cleared for save memory' do
|
56
|
+
t = RemoteTable.new 'http://spreadsheets.google.com/pub?key=tObVAGyqOkCBtGid0tJUZrw'
|
57
|
+
t.to_a
|
58
|
+
assert_equal Array, t.instance_variable_get(:@to_a).class
|
59
|
+
t.free
|
60
|
+
assert_equal NilClass, t.instance_variable_get(:@to_a).class
|
61
|
+
end
|
46
62
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 6
|
10
|
+
version: 1.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Seamus Abshere
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-03-
|
19
|
+
date: 2011-03-31 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|