sower 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10f00dc3d82de960da33a6f92f8e46e52e431049
4
- data.tar.gz: e7cefb80f41c0a699129f552b37347aad870732c
3
+ metadata.gz: 77c34dd60190487803ca0a9bfed6c5371f425ab8
4
+ data.tar.gz: 9476af4a52a245e75085c9569513f5cd23f0f8fa
5
5
  SHA512:
6
- metadata.gz: d1ee9354f077592354c3ee5a6acd8c3afd19e1575fa8641d6a4e4ab27f8f9bb92db0a47ccb298a30bd9bf8662ce1e09ce6a14c2b1912fdd49fa6d412b885006e
7
- data.tar.gz: b0c7cc0782e2725e819e3e472c528150cf0ff682264f07f48b91188393988e8b9a53c772ce70f43280a3240738e7ccd198b841e58e03378ae1d73b8cf7b84a7a
6
+ metadata.gz: e7bd9df48c940170a82f4b7cd91a635b767bf1c73d2fe734b8ff2ed96b739f1c02dfcd098dcff25fc27629ae6587288cb40e8744335cc154adeb014d88c13a25
7
+ data.tar.gz: d95d3a2c635e3bd6a36b064fd645bb662691edd6f10e0f91b2fecf7c50a4463170941a598b369a8fcfcdb8ef631ae00d1e8f995ebe722e37736ece4a96ecca27
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .idea
5
6
  .yardoc
6
7
  Gemfile.lock
7
8
  InstalledFiles
@@ -1,23 +1,28 @@
1
- require "sower/version"
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 = File.join(seeds_path, "#{filename}.sql")
7
- csv_path = File.join(seeds_path, "#{filename}.csv")
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
@@ -1,3 +1,3 @@
1
1
  module Sower
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-24 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler