deep_freezer 0.4.0 → 0.4.1

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: 8b7d1d66e0c1b9a3ee795365ea24541c4e59e08a
4
- data.tar.gz: f677d6282cf2607163a30fecc666969c3753bb6d
3
+ metadata.gz: 49debc6776b32159d953f0488f6ec752f6e85279
4
+ data.tar.gz: cbc17697c8c9ba97d44eceb730bf60b7284fa8f7
5
5
  SHA512:
6
- metadata.gz: 375c3ef67708d8e4da18600ab063c8c3d6bcdb3eb02753a7511b81077a4e75c081950ea320d882a9106dc2fd26bb9186f1e70e7965379cd7733aeb6e5022d7e9
7
- data.tar.gz: 267eef5f307304f5f6b728a8913d49c48146f794f854c76c8f309da276bcef8e4e9ca05932022bfa67397768de66618689278f03909401b8b0455b1d030f355e
6
+ metadata.gz: ee0466cb67e5dc42ae5afd0bc6afec72298165133eec5018a9e720dec9a45dd36e4eb098cc446c0d08b09a5494635f650eb3c53e8fa652c87a3d9fb66545b43f
7
+ data.tar.gz: 2ed1a8af8d99c6d4c243ee15d157590a14c86d693ef4477d6dda29ecaceed98a0ee29e4165ddc04a345dfcf20517b52318ae825cd4a09d5fc8a1c30b5a375cf4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deep_freezer (0.4.0)
4
+ deep_freezer (0.4.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,40 @@
1
+ class DeepFreezer::Defrost
2
+
3
+ def self.load!
4
+
5
+ path = DeepFreezer::Base.fixture_path.join("**/*.yml")
6
+ Dir.glob(path).each do |file|
7
+ objects = YAML.load(File.read(file))
8
+ puts "Loading #{objects.first.keys.first}"
9
+ objects.each do |o|
10
+
11
+ klass = o.keys.first
12
+ attrs = o[klass]
13
+ obj = klass.constantize.new
14
+
15
+ attrs.keys.each do |a|
16
+ obj.send("#{a}=", attrs[a])
17
+ end
18
+
19
+ sql = self.sql_for(obj)
20
+ ActiveRecord::Base.connection.execute sql
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ def self.sql_for(record)
27
+ values = record.send(:arel_attributes_with_values_for_create, record.attribute_names)
28
+
29
+ model = record.class
30
+ scope = model.unscoped
31
+
32
+ im = scope.arel.create_insert
33
+ im.into model.arel_table
34
+
35
+ substitutes, binds = scope.substitute_values(values)
36
+ im.insert substitutes
37
+
38
+ record.class.connection.to_sql(im, binds)
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module DeepFreezer
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_freezer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Provan
@@ -75,6 +75,7 @@ files:
75
75
  - deep_freezer.gemspec
76
76
  - lib/deep_freezer.rb
77
77
  - lib/deep_freezer/base.rb
78
+ - lib/deep_freezer/defrost.rb
78
79
  - lib/deep_freezer/version.rb
79
80
  homepage: https://github.com/itison/deep_freezer
80
81
  licenses: