struggle 2.3.8 → 2.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/struggle/sql.rb +21 -26
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a89438c6c72b1a4d8bbe6ddc7cc3b1f08f0ee20f
4
- data.tar.gz: 1d2d6c93ef994ad1181336fee20b2787fce06385
3
+ metadata.gz: c81c7d2477eae2412e578bf73326826fc7dc2c3e
4
+ data.tar.gz: 2a864ad7bc30bd6535330682c2ac54e89926601b
5
5
  SHA512:
6
- metadata.gz: 426860d803e6bd015244adddb63d7ea3815598b8abccc12da3cc777d56bf7b3ade409b02b503a8d188b2737c46f52ca10337104daa508c307b17436d655ea664
7
- data.tar.gz: 057131b1545971cdd33a81d2b9c734cfefec72c9439725ecfdbb93ebe8b54059f36296b061f90df8ce19bfd13ef812e18e190096c48b68a5ea21d20717836835
6
+ metadata.gz: 2e74496d38feb6d22144704cfb8424b78039429442b0c635f210c0c6448959eee26aa3dfb24413ec982794ee221d48dc6aa74ee0a47e2894c3db345553355084
7
+ data.tar.gz: 4b0638b97d1aff7c773ca4516d5ee895bceaf5d80165c5f6c1d8d511ced0ddd549debab089bc887957f8982e6ddf3c5816322fb05962f6f232f4cb94323d7966
data/lib/struggle/sql.rb CHANGED
@@ -16,33 +16,28 @@ module Struggle
16
16
  # class_name is ActiveRecord; file is backup sql file
17
17
  def dump(config)
18
18
  config["file"] = config["file"].blank? ? "db.sql" : config["file"]
19
- config["class_name"].each do |class_name|
20
- obj = eval(class_name)
21
- obj.all.each do |o|
22
- attrs = o.attributes
23
- names = []
24
- values = []
25
- attrs.each do |k, v|
26
- names << k
27
- value = v
28
- if v.class == Date
29
- value = v.strftime("%Y-%m-%d")
30
- value = "TO_DATE('#{value}', 'YYYY-MM-DD')" if config["adapter"] && config["adapter"].downcase == "oracle"
31
- elsif v.class == ActiveSupport::TimeWithZone
32
- value = v.strftime("%Y-%m-%d %H:%M:%S")
33
- value = "TO_TIMESTAMP('#{value}', 'YYYY-MM-DD HH24:MI:SS.FF6')" if config["adapter"] && config["adapter"].downcase == "oracle"
34
- else
35
- value = "'#{v}'"
19
+ File.open(config["file"], "w+") do |file|
20
+ config["class_name"].each do |class_name|
21
+ obj = eval(class_name)
22
+ obj.all.each do |o|
23
+ attrs = o.attributes
24
+ names = []
25
+ values = []
26
+ attrs.each do |k, v|
27
+ names << k
28
+ value = v
29
+ if v.class == Date
30
+ value = v.strftime("%Y-%m-%d")
31
+ value = "TO_DATE('#{value}', 'YYYY-MM-DD')" if config["adapter"] && config["adapter"].downcase == "oracle"
32
+ elsif v.class == ActiveSupport::TimeWithZone
33
+ value = v.strftime("%Y-%m-%d %H:%M:%S")
34
+ value = "TO_TIMESTAMP('#{value}', 'YYYY-MM-DD HH24:MI:SS.FF6')" if config["adapter"] && config["adapter"].downcase == "oracle"
35
+ else
36
+ value = "'#{v}'"
37
+ end
38
+ values << value
36
39
  end
37
- values << value
38
- end
39
- begin
40
- f = File.new(config["file"], "w+")
41
- f.write("INSERT INTO #{obj.table_name} (#{names.join(',')}) VALUES (#{values.join(',')});\r\n")
42
- f.close
43
- f = nil
44
- rescue
45
- return "#{$!}:#{config["file"]}"
40
+ file.puts "INSERT INTO #{obj.table_name} (#{names.join(',')}) VALUES (#{values.join(',')});\r\n"
46
41
  end
47
42
  end
48
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: struggle
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.8
4
+ version: 2.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - lean