dumpable 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/dumpable.gemspec +2 -2
- data/lib/dumpable.rb +18 -11
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/dumpable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "dumpable"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Hunter"]
|
12
|
-
s.date = "2013-06-
|
12
|
+
s.date = "2013-06-21"
|
13
13
|
s.description = "Generate the SQL to insert a single record and all of its dependencies"
|
14
14
|
s.email = "andrew.hunter@livingsocial.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/dumpable.rb
CHANGED
@@ -37,15 +37,15 @@ module Dumpable
|
|
37
37
|
elsif dumps.is_a?(Hash)
|
38
38
|
dumps.each do |key, value|
|
39
39
|
recursive_dump(object, id_padding, key)
|
40
|
-
object.send(key).
|
40
|
+
Array(object.send(key)).each { |child| recursive_dump(child, id_padding, value) }
|
41
41
|
end
|
42
42
|
elsif dumps.is_a?(Symbol) || dumps.is_a?(String)
|
43
|
-
object.send(dumps).
|
43
|
+
Array(object.send(dumps)).each do |child_object|
|
44
44
|
reflection = object.class.reflections[dumps]
|
45
45
|
if reflection.macro == :belongs_to
|
46
|
-
object.send("#{reflection.
|
46
|
+
object.send("#{reflection.association_foreign_key}=", object.id + id_padding)
|
47
47
|
elsif [:has_many, :has_one].include? reflection.macro
|
48
|
-
child_object.send("#{reflection.
|
48
|
+
child_object.send("#{reflection.association_primary_key}=", object.id + id_padding)
|
49
49
|
end
|
50
50
|
puts child_object.send(:generate_insert_query, id_padding)
|
51
51
|
end
|
@@ -55,13 +55,20 @@ module Dumpable
|
|
55
55
|
# http://invisipunk.blogspot.com/2008/04/activerecord-raw-insertupdate.html
|
56
56
|
def dump_value_string(value)
|
57
57
|
case value.class.to_s
|
58
|
-
when "Time"
|
59
|
-
|
60
|
-
when "
|
61
|
-
|
62
|
-
when "
|
63
|
-
|
64
|
-
|
58
|
+
when "Time"
|
59
|
+
"'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
|
60
|
+
when "NilClass"
|
61
|
+
"NULL"
|
62
|
+
when "Fixnum"
|
63
|
+
value
|
64
|
+
when "String"
|
65
|
+
"'#{value.gsub(/'/, "\\\\'")}'"
|
66
|
+
when "FalseClass"
|
67
|
+
'0'
|
68
|
+
when "TrueClass"
|
69
|
+
'1'
|
70
|
+
else
|
71
|
+
"'#{value}'"
|
65
72
|
end
|
66
73
|
end
|
67
74
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dumpable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
segments:
|
128
128
|
- 0
|
129
|
-
hash:
|
129
|
+
hash: -1145907992056819388
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
none: false
|
132
132
|
requirements:
|