importeroo 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +24 -1
- data/README.md +16 -2
- data/importeroo.gemspec +1 -0
- data/lib/importeroo/importer.rb +17 -1
- data/lib/importeroo/version.rb +1 -1
- data/spec/importeroo/importer_spec.rb +48 -16
- metadata +36 -9
- checksums.yaml +0 -7
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
importeroo (0.
|
4
|
+
importeroo (0.2.0)
|
5
|
+
google-spreadsheet-ruby
|
5
6
|
roo
|
6
7
|
|
7
8
|
GEM
|
@@ -27,17 +28,39 @@ GEM
|
|
27
28
|
builder (3.1.4)
|
28
29
|
coderay (1.0.9)
|
29
30
|
diff-lcs (1.2.4)
|
31
|
+
faraday (0.8.8)
|
32
|
+
multipart-post (~> 1.2.0)
|
33
|
+
google-spreadsheet-ruby (0.3.1)
|
34
|
+
google_drive (>= 0.3.0)
|
35
|
+
google_drive (0.3.6)
|
36
|
+
nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
|
37
|
+
oauth (>= 0.3.6)
|
38
|
+
oauth2 (>= 0.5.0)
|
39
|
+
httpauth (0.2.0)
|
30
40
|
i18n (0.6.4)
|
41
|
+
jwt (0.1.8)
|
42
|
+
multi_json (>= 1.5)
|
31
43
|
method_source (0.8.1)
|
32
44
|
mini_portile (0.5.1)
|
33
45
|
minitest (4.7.5)
|
34
46
|
multi_json (1.7.7)
|
47
|
+
multi_xml (0.5.5)
|
48
|
+
multipart-post (1.2.0)
|
35
49
|
nokogiri (1.6.0)
|
36
50
|
mini_portile (~> 0.5.0)
|
51
|
+
oauth (0.4.7)
|
52
|
+
oauth2 (0.9.2)
|
53
|
+
faraday (~> 0.8)
|
54
|
+
httpauth (~> 0.2)
|
55
|
+
jwt (~> 0.1.4)
|
56
|
+
multi_json (~> 1.0)
|
57
|
+
multi_xml (~> 0.5)
|
58
|
+
rack (~> 1.2)
|
37
59
|
pry (0.9.12.2)
|
38
60
|
coderay (~> 1.0.5)
|
39
61
|
method_source (~> 0.8)
|
40
62
|
slop (~> 3.4)
|
63
|
+
rack (1.5.2)
|
41
64
|
rake (10.1.0)
|
42
65
|
roo (1.11.2)
|
43
66
|
nokogiri
|
data/README.md
CHANGED
@@ -15,13 +15,26 @@ Add to gemfile:
|
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
18
|
-
In db/seeds.rb:
|
18
|
+
### In db/seeds.rb:
|
19
19
|
|
20
20
|
require 'importeroo/importer'
|
21
21
|
|
22
22
|
Importeroo::Importer.new(MyActiveRecordClass, "FileType", "path/to/file").import!
|
23
23
|
|
24
|
-
|
24
|
+
### For Google Docs:
|
25
|
+
|
26
|
+
Importeroo::Importer.new(MyActiveRecordClass, "Google", "KEYcodeFROMgdocsURL")
|
27
|
+
|
28
|
+
The code for the google doc is the long alphanumeric key listed in the URL. For example:
|
29
|
+
|
30
|
+
https://docs.google.com/spreadsheet/ccc?key=0AmX1I4h6m35OdFhlbDdLdnZfTUFnSVRzd0hqMjM1bUE#gid=0, the key is 0AmX1I4h6m35OdFhlbDdLdnZfTUFnSVRzd0hqMjM1bUE.
|
31
|
+
|
32
|
+
If your doc is not visible to anyone with the URL, you will also need to set the google username and password in config/importeroo.rb, or anywhere:
|
33
|
+
|
34
|
+
Importeroo.google_username = ENV["GOOGLE_USERNAME"]
|
35
|
+
Importeroo.google_password = ENV["GOOGLE_PASSWORD"]
|
36
|
+
|
37
|
+
### For CSV, Excel, or OpenOffice:
|
25
38
|
|
26
39
|
Importeroo::Importer.new(MyActiveRecordClass, "CSV", "path/to/file.csv")
|
27
40
|
Importeroo::Importer.new(MyActiveRecordClass, "Excelx", "path/to/file.xlsx") # current Excel
|
@@ -29,5 +42,6 @@ Options are:
|
|
29
42
|
Importeroo::Importer.new(MyActiveRecordClass, "OpenOffice", "path/to/file.ods")
|
30
43
|
|
31
44
|
Recommended path to file:
|
45
|
+
|
32
46
|
data/import/my_active_record_class_pluralized.csv
|
33
47
|
|
data/importeroo.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.required_ruby_version = '>= 1.9.2'
|
19
19
|
|
20
20
|
gem.add_dependency 'roo'
|
21
|
+
gem.add_dependency 'google-spreadsheet-ruby'
|
21
22
|
|
22
23
|
gem.add_development_dependency 'rspec', '~> 2.11'
|
23
24
|
gem.add_development_dependency 'with_model', '~> 0.3'
|
data/lib/importeroo/importer.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'roo'
|
2
2
|
|
3
3
|
module Importeroo
|
4
|
+
mattr_accessor :google_username, :google_password
|
5
|
+
|
4
6
|
class Importer < Struct.new(:klass, :data_source_type, :data_source)
|
5
7
|
FIELDS_TO_EXCLUDE = ["created_at", "updated_at"]
|
6
8
|
|
@@ -17,7 +19,21 @@ module Importeroo
|
|
17
19
|
private
|
18
20
|
|
19
21
|
def data
|
20
|
-
@data ||=
|
22
|
+
@data ||= load_data
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_data
|
26
|
+
google_data || non_google_data
|
27
|
+
end
|
28
|
+
|
29
|
+
def google_data
|
30
|
+
if data_source_type == "Google"
|
31
|
+
roo_class.new(data_source, Importeroo.google_username, Importeroo.google_password)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def non_google_data
|
36
|
+
roo_class.new(data_source, nil, :ignore)
|
21
37
|
end
|
22
38
|
|
23
39
|
def roo_class
|
data/lib/importeroo/version.rb
CHANGED
@@ -8,36 +8,68 @@ describe Importeroo::Importer do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
shared_examples_for "a table importer from an external source" do
|
12
|
+
it "deletes old data and imports the new data" do
|
13
|
+
BicycleType.count.should == 4
|
14
|
+
BicycleType.find(1).bicycle_type.should == "road bike"
|
15
|
+
BicycleType.find(2).bicycle_type.should == "mountain bike"
|
16
|
+
BicycleType.find(3).bicycle_type.should == "touring bike"
|
17
|
+
BicycleType.find(4).bicycle_type.should == "beach cruiser"
|
18
|
+
|
19
|
+
BicycleType.all.map(&:bicycle_type).should_not include("velocipede")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
describe "#import!" do
|
12
24
|
context "when a CSV" do
|
13
|
-
|
25
|
+
before do
|
14
26
|
BicycleType.create(id: 5, bicycle_type: "velocipede")
|
15
27
|
|
16
28
|
described_class.new(BicycleType, "CSV", "spec/fixtures/bicycles.csv").import!
|
17
|
-
|
18
|
-
BicycleType.count.should == 4
|
19
|
-
BicycleType.find(1).bicycle_type.should == "road bike"
|
20
|
-
BicycleType.find(2).bicycle_type.should == "mountain bike"
|
21
|
-
BicycleType.find(3).bicycle_type.should == "touring bike"
|
22
|
-
BicycleType.find(4).bicycle_type.should == "beach cruiser"
|
23
|
-
|
24
|
-
BicycleType.all.map(&:bicycle_type).should_not include("velocipede")
|
25
29
|
end
|
30
|
+
|
31
|
+
it_should_behave_like "a table importer from an external source"
|
26
32
|
end
|
27
33
|
|
28
34
|
context "when an Excel file" do
|
29
|
-
|
35
|
+
before do
|
30
36
|
BicycleType.create(id: 5, bicycle_type: "velocipede")
|
31
37
|
|
32
38
|
described_class.new(BicycleType, "Excelx", "spec/fixtures/bicycles.xlsx").import!
|
39
|
+
end
|
40
|
+
|
41
|
+
it_should_behave_like "a table importer from an external source"
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when a Google Spreadsheet" do
|
45
|
+
context "when explicitly set" do
|
46
|
+
before do
|
47
|
+
Importeroo.google_username = "port.of.call.test@gmail.com"
|
48
|
+
Importeroo.google_password = "importexport123"
|
49
|
+
|
50
|
+
BicycleType.create(id: 5, bicycle_type: "velocipede")
|
51
|
+
|
52
|
+
described_class
|
53
|
+
.new(BicycleType, "Google", "0AmX1I4h6m35OdFhlbDdLdnZfTUFnSVRzd0hqMjM1bUE").import!
|
54
|
+
end
|
55
|
+
|
56
|
+
it_should_behave_like "a table importer from an external source"
|
57
|
+
|
58
|
+
after do
|
59
|
+
Importeroo.google_username = nil
|
60
|
+
Importeroo.google_password = nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when not explicitly set", focus: true do
|
65
|
+
before do
|
66
|
+
BicycleType.create(id: 5, bicycle_type: "velocipede")
|
33
67
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
BicycleType.find(3).bicycle_type.should == "touring bike"
|
38
|
-
BicycleType.find(4).bicycle_type.should == "beach cruiser"
|
68
|
+
described_class
|
69
|
+
.new(BicycleType, "Google", "0AmX1I4h6m35OdFhlbDdLdnZfTUFnSVRzd0hqMjM1bUE").import!
|
70
|
+
end
|
39
71
|
|
40
|
-
|
72
|
+
it_should_behave_like "a table importer from an external source"
|
41
73
|
end
|
42
74
|
end
|
43
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: importeroo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Trace Wax
|
@@ -9,25 +10,44 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
13
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: roo
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- - '>='
|
20
|
+
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- - '>='
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: google-spreadsheet-ruby
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
26
45
|
- !ruby/object:Gem::Version
|
27
46
|
version: '0'
|
28
47
|
- !ruby/object:Gem::Dependency
|
29
48
|
name: rspec
|
30
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
31
51
|
requirements:
|
32
52
|
- - ~>
|
33
53
|
- !ruby/object:Gem::Version
|
@@ -35,6 +55,7 @@ dependencies:
|
|
35
55
|
type: :development
|
36
56
|
prerelease: false
|
37
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
38
59
|
requirements:
|
39
60
|
- - ~>
|
40
61
|
- !ruby/object:Gem::Version
|
@@ -42,6 +63,7 @@ dependencies:
|
|
42
63
|
- !ruby/object:Gem::Dependency
|
43
64
|
name: with_model
|
44
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
45
67
|
requirements:
|
46
68
|
- - ~>
|
47
69
|
- !ruby/object:Gem::Version
|
@@ -49,6 +71,7 @@ dependencies:
|
|
49
71
|
type: :development
|
50
72
|
prerelease: false
|
51
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
52
75
|
requirements:
|
53
76
|
- - ~>
|
54
77
|
- !ruby/object:Gem::Version
|
@@ -75,26 +98,30 @@ files:
|
|
75
98
|
homepage: https://github.com/tracedwax/importeroo
|
76
99
|
licenses:
|
77
100
|
- MIT
|
78
|
-
metadata: {}
|
79
101
|
post_install_message:
|
80
102
|
rdoc_options: []
|
81
103
|
require_paths:
|
82
104
|
- lib
|
83
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
84
107
|
requirements:
|
85
|
-
- - '>='
|
108
|
+
- - ! '>='
|
86
109
|
- !ruby/object:Gem::Version
|
87
110
|
version: 1.9.2
|
88
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
89
113
|
requirements:
|
90
|
-
- - '>='
|
114
|
+
- - ! '>='
|
91
115
|
- !ruby/object:Gem::Version
|
92
116
|
version: '0'
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
hash: -3869497551771485290
|
93
120
|
requirements: []
|
94
121
|
rubyforge_project:
|
95
|
-
rubygems_version:
|
122
|
+
rubygems_version: 1.8.25
|
96
123
|
signing_key:
|
97
|
-
specification_version:
|
124
|
+
specification_version: 3
|
98
125
|
summary: Import items from a CSV into an activerecord model
|
99
126
|
test_files:
|
100
127
|
- spec/fixtures/bicycles.csv
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: fd6b6728bddfa4fc22a7e8944509a2ad79a317fb
|
4
|
-
data.tar.gz: 7ede37017e89ee773e119846686716eb84dea519
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 855fd59a09ef6005611622d59f64242ac81c37a6e2de87b6a76ad4b41bfadd61e79fe348ef5bb59884ab1bbfe5e35495435bedad437a55f0a12cbe63f5cdaab9
|
7
|
-
data.tar.gz: 33910273ca0be85785c973fb41f221449930ee0fa7550eee45ffe0e71a10f29fa1bb5b7c78b9e1156424f8ec1757ba52856406c49069b6bb302317b6748b5ba7
|