remote_table 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/remote_table.rb +12 -12
- data/lib/remote_table/transformer.rb +8 -2
- data/lib/remote_table/version.rb +1 -1
- metadata +4 -4
data/lib/remote_table.rb
CHANGED
@@ -4,6 +4,7 @@ require 'active_support/version'
|
|
4
4
|
active_support/core_ext/hash
|
5
5
|
active_support/core_ext/string
|
6
6
|
active_support/core_ext/module
|
7
|
+
active_support/core_ext/array/wrap
|
7
8
|
}.each do |active_support_3_requirement|
|
8
9
|
require active_support_3_requirement
|
9
10
|
end if ::ActiveSupport::VERSION::MAJOR == 3
|
@@ -46,17 +47,12 @@ class RemoteTable
|
|
46
47
|
# See the <tt>Properties</tt> object for the sorts of options you can pass.
|
47
48
|
def initialize(*args)
|
48
49
|
@options = args.last.is_a?(::Hash) ? args.last.dup : {}
|
49
|
-
|
50
|
-
|
50
|
+
@options.stringify_keys!
|
51
|
+
@url = if args.first.is_a? ::String
|
52
|
+
args.first.dup
|
51
53
|
else
|
52
|
-
@
|
53
|
-
end
|
54
|
-
# deprecated
|
55
|
-
if options[:transform]
|
56
|
-
transformer.legacy_transformer = options[:transform][:class].new options[:transform].except(:class)
|
57
|
-
transformer.legacy_transformer.add_hints! @options
|
54
|
+
@options['url'].dup
|
58
55
|
end
|
59
|
-
@options.stringify_keys!
|
60
56
|
@url.freeze
|
61
57
|
@options.freeze
|
62
58
|
at_exit { ::RemoteTable.cleaner.cleanup }
|
@@ -66,7 +62,7 @@ class RemoteTable
|
|
66
62
|
format.each do |row|
|
67
63
|
row['row_hash'] = ::RemoteTable.hasher.hash row
|
68
64
|
# allow the transformer to return multiple "virtual rows" for every real row
|
69
|
-
transformer.transform(row).each do |virtual_row|
|
65
|
+
::Array.wrap(transformer.transform(row)).each do |virtual_row|
|
70
66
|
if properties.errata
|
71
67
|
next if properties.errata.rejects? virtual_row
|
72
68
|
properties.errata.correct! virtual_row
|
@@ -85,9 +81,13 @@ class RemoteTable
|
|
85
81
|
end
|
86
82
|
|
87
83
|
# Get the whole row array back
|
88
|
-
def
|
89
|
-
to_a
|
84
|
+
def to_a
|
85
|
+
return @to_a if @to_a.is_a? ::Array
|
86
|
+
@to_a = []
|
87
|
+
each { |row| @to_a.push row }
|
88
|
+
@to_a.freeze
|
90
89
|
end
|
90
|
+
alias :rows :to_a
|
91
91
|
|
92
92
|
# Used internally as a sort of garbage collector.
|
93
93
|
def self.cleaner
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class RemoteTable
|
2
2
|
class Transformer
|
3
3
|
attr_reader :t
|
4
|
-
attr_accessor :legacy_transformer
|
5
4
|
def initialize(t)
|
6
5
|
@t = t
|
7
6
|
end
|
@@ -10,8 +9,15 @@ class RemoteTable
|
|
10
9
|
if legacy_transformer
|
11
10
|
legacy_transformer.apply row
|
12
11
|
else
|
13
|
-
|
12
|
+
row
|
14
13
|
end
|
15
14
|
end
|
15
|
+
def legacy_transformer
|
16
|
+
return @legacy_transformer if @legacy_transformer
|
17
|
+
return unless t.options['transform']
|
18
|
+
transform_options = t.options['transform'].dup
|
19
|
+
transform_options.stringify_keys!
|
20
|
+
@legacy_transformer = transform_options['class'].new transform_options.except('class')
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/remote_table/version.rb
CHANGED
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: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
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-01-
|
19
|
+
date: 2011-01-26 00:00:00 -06:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|