origami-importer 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/origami-importer.rb +2 -1
- data/lib/origami-importer/batch.rb +2 -3
- data/lib/origami-importer/writer.rb +10 -2
- data/origami-importer.gemspec +1 -1
- data/spec/writer_spec.rb +5 -5
- metadata +7 -6
data/lib/origami-importer.rb
CHANGED
@@ -27,8 +27,9 @@ module Origami
|
|
27
27
|
host = options[:host]
|
28
28
|
realm = options[:realm]
|
29
29
|
source = options[:source]
|
30
|
+
session = options[:session]
|
30
31
|
|
31
|
-
batch = Batch.new(:host => host, :realm => realm, :source => source)
|
32
|
+
batch = Batch.new(:host => host, :realm => realm, :source => source, :session => session)
|
32
33
|
|
33
34
|
reader = options[:reader]
|
34
35
|
writer = Writer.new(batch)
|
@@ -7,7 +7,7 @@ module Origami
|
|
7
7
|
self.endpoint = options[:host]
|
8
8
|
self.realm = options[:realm]
|
9
9
|
self.source = options[:source]
|
10
|
-
self.session = options[:session]
|
10
|
+
self.session = options[:session]
|
11
11
|
end
|
12
12
|
|
13
13
|
def client
|
@@ -28,9 +28,8 @@ module Origami
|
|
28
28
|
remote.relay || {:previous_import_at => Time.now.utc}
|
29
29
|
end
|
30
30
|
|
31
|
-
# what about :delete => other_records?
|
32
31
|
def save(records)
|
33
|
-
client.post "/#{realm}/batches/#{remote.id}/items",
|
32
|
+
client.post "/#{realm}/batches/#{remote.id}/items", records
|
34
33
|
end
|
35
34
|
|
36
35
|
def close(data)
|
@@ -9,11 +9,19 @@ module Origami
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def <<(records)
|
12
|
-
|
12
|
+
records = [records].flatten.compact
|
13
|
+
result = {}
|
14
|
+
records.each do |record|
|
15
|
+
key = record.keys.first
|
16
|
+
value = record.values.first
|
17
|
+
result[key] ||= []
|
18
|
+
result[key] << value
|
19
|
+
end
|
20
|
+
save result
|
13
21
|
end
|
14
22
|
|
15
23
|
def save(records)
|
16
|
-
|
24
|
+
unless records.empty?
|
17
25
|
batch.save records
|
18
26
|
end
|
19
27
|
end
|
data/origami-importer.gemspec
CHANGED
data/spec/writer_spec.rb
CHANGED
@@ -7,17 +7,17 @@ describe Origami::Importer::Writer do
|
|
7
7
|
subject { Origami::Importer::Writer.new(batch) }
|
8
8
|
|
9
9
|
it "saves records" do
|
10
|
-
batch.should_receive(:save).with [:
|
11
|
-
subject << [:
|
10
|
+
batch.should_receive(:save).with({:put => [:record1, :record2], :delete => [:record3]})
|
11
|
+
subject << [{:put => :record1}, {:put => :record2}, {:delete => :record3}]
|
12
12
|
end
|
13
13
|
|
14
14
|
it "handles single entries" do
|
15
|
-
batch.should_receive(:save).with [:
|
16
|
-
subject << :
|
15
|
+
batch.should_receive(:save).with({:put => [:record1]})
|
16
|
+
subject << {:put => :record1}
|
17
17
|
end
|
18
18
|
|
19
19
|
it "doesn't bother unless there are actually records" do
|
20
20
|
batch.should_not_receive(:save)
|
21
|
-
subject << [nil, nil
|
21
|
+
subject << [nil, nil]
|
22
22
|
end
|
23
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: origami-importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70210109043220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70210109043220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: pebblebed
|
27
|
-
requirement: &
|
27
|
+
requirement: &70210109041300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70210109041300
|
36
36
|
description: Superglue for origami imports
|
37
37
|
email:
|
38
38
|
- katrina.owen@gmail.com
|
@@ -79,3 +79,4 @@ summary: Superglue for origami imports
|
|
79
79
|
test_files:
|
80
80
|
- spec/spec_helper.rb
|
81
81
|
- spec/writer_spec.rb
|
82
|
+
has_rdoc:
|