sower 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/sower.rb +17 -6
- data/lib/sower/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77c34dd60190487803ca0a9bfed6c5371f425ab8
|
4
|
+
data.tar.gz: 9476af4a52a245e75085c9569513f5cd23f0f8fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7bd9df48c940170a82f4b7cd91a635b767bf1c73d2fe734b8ff2ed96b739f1c02dfcd098dcff25fc27629ae6587288cb40e8744335cc154adeb014d88c13a25
|
7
|
+
data.tar.gz: d95d3a2c635e3bd6a36b064fd645bb662691edd6f10e0f91b2fecf7c50a4463170941a598b369a8fcfcdb8ef631ae00d1e8f995ebe722e37736ece4a96ecca27
|
data/.gitignore
CHANGED
data/lib/sower.rb
CHANGED
@@ -1,23 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require 'sower/version'
|
2
2
|
require 'csv'
|
3
3
|
|
4
4
|
module Sower
|
5
5
|
def self.seed(clazz, filename, options = {})
|
6
|
-
sql_path
|
7
|
-
csv_path
|
6
|
+
sql_path = File.join(seeds_path, "#{filename}.sql")
|
7
|
+
csv_path = File.join(seeds_path, "#{filename}.csv")
|
8
8
|
text_path = File.join(seeds_path, "#{filename}.txt")
|
9
9
|
|
10
|
+
old_table_name = clazz.table_name
|
11
|
+
if @schema.present?
|
12
|
+
clazz.table_name = "#{@schema}.#{clazz.table_name}"
|
13
|
+
end
|
14
|
+
|
10
15
|
if clazz.respond_to?(:enumeration_model_updates_permitted=)
|
11
16
|
clazz.enumeration_model_updates_permitted = true
|
12
17
|
end
|
13
18
|
|
14
19
|
if File.exists?(sql_path)
|
15
|
-
puts "Importing #{filename} as SQL"
|
20
|
+
puts "Importing #{filename} to #{clazz.table_name} as SQL"
|
16
21
|
|
17
22
|
data = File.read(sql_path)
|
18
23
|
ActiveRecord::Base.connection.execute data
|
19
24
|
elsif File.exists?(csv_path)
|
20
|
-
puts "Importing #{filename} as CSV"
|
25
|
+
puts "Importing #{filename} to #{clazz.table_name} as CSV"
|
21
26
|
|
22
27
|
index = 0
|
23
28
|
CSV.foreach(csv_path) do |row|
|
@@ -39,7 +44,7 @@ module Sower
|
|
39
44
|
index += 1
|
40
45
|
end
|
41
46
|
else
|
42
|
-
puts "Importing #{filename} as Text"
|
47
|
+
puts "Importing #{filename} to #{clazz.table_name} as Text"
|
43
48
|
|
44
49
|
File.foreach(text_path).each_with_index do |line, index|
|
45
50
|
m = clazz.new(:name => line.chomp)
|
@@ -53,6 +58,8 @@ module Sower
|
|
53
58
|
ActiveRecord::Base.connection.execute \
|
54
59
|
"SELECT setval('#{clazz.table_name}_id_seq'::regclass, MAX(id)) FROM #{clazz.table_name};"
|
55
60
|
end
|
61
|
+
|
62
|
+
clazz.table_name = old_table_name
|
56
63
|
end
|
57
64
|
|
58
65
|
def self.seeds_path=(path)
|
@@ -69,4 +76,8 @@ module Sower
|
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
79
|
+
def self.schema=(schema)
|
80
|
+
@schema = schema
|
81
|
+
end
|
82
|
+
|
72
83
|
end
|
data/lib/sower/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sower
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Belzer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|