deep_freezer 0.4.2 → 1.0.0

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: 757ca1be556d21ba64174bd0a31162d0032d0a95
4
- data.tar.gz: d0499d03070c894044b6f4147c9de99b68ec61a9
3
+ metadata.gz: e1efc00f291e048d002a8a4c8e3fbec16550e2d4
4
+ data.tar.gz: 2c0e6124cb1fbdac3fcb56d48824203d5ce9c377
5
5
  SHA512:
6
- metadata.gz: 8906f7a09cff6e5a6407d0af803f7add5fe59019645b577b645d115648aff6fb67b89ad02620ffcc4dd587321c6861fbf0bb4978b017ff6cd78babff6531f910
7
- data.tar.gz: fdd036f8df4813a98eb33d4a59a7e44d4b661dd7aecab17ed406ed7f91de79c3b55a3d5f0879027eb64f291ab6cbe76ec8be367c6afbd7939cf4f0c9ba94aed9
6
+ metadata.gz: fc16fed0eff7cdc4715518d1ad7de7dc9fd1e5e4e6befa4ed415b70f6fbd24a11715ae637da53b4e7245d12f74f603359cd422e22b006fec7f675282407fd793
7
+ data.tar.gz: a198b857b8fd00f1f7787ad3715765f45526cb23fef2d77b3a0e822501f17a84962392c609990e7ca3bdd94a7c731d503ca32e60f51cc4cb959b47ca19a362ef
@@ -1,12 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deep_freezer (0.4.2)
4
+ deep_freezer (1.0.0)
5
+ activerecord (> 4.2.10, < 6.0.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ activemodel (5.1.5)
11
+ activesupport (= 5.1.5)
12
+ activerecord (5.1.5)
13
+ activemodel (= 5.1.5)
14
+ activesupport (= 5.1.5)
15
+ arel (~> 8.0)
16
+ activerecord-nulldb-adapter (0.3.8)
17
+ activerecord (>= 2.0.0)
18
+ activesupport (5.1.5)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (~> 0.7)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ arel (8.0.0)
24
+ coderay (1.1.2)
25
+ concurrent-ruby (1.0.5)
9
26
  diff-lcs (1.3)
27
+ i18n (0.9.5)
28
+ concurrent-ruby (~> 1.0)
29
+ method_source (0.9.0)
30
+ minitest (5.11.3)
31
+ pry (0.11.3)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.9.0)
10
34
  rake (10.4.2)
11
35
  rspec (3.5.0)
12
36
  rspec-core (~> 3.5.0)
@@ -21,13 +45,18 @@ GEM
21
45
  diff-lcs (>= 1.2.0, < 2.0)
22
46
  rspec-support (~> 3.5.0)
23
47
  rspec-support (3.5.0)
48
+ thread_safe (0.3.6)
49
+ tzinfo (1.2.5)
50
+ thread_safe (~> 0.1)
24
51
 
25
52
  PLATFORMS
26
53
  ruby
27
54
 
28
55
  DEPENDENCIES
56
+ activerecord-nulldb-adapter
29
57
  bundler (~> 1.16)
30
58
  deep_freezer!
59
+ pry
31
60
  rake (~> 10.0)
32
61
  rspec (~> 3.0)
33
62
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # Deep Freezer
1
+ # Deep Freezer v1.0.0
2
2
  ## Freeze ActiveRecord models to Rails compatible fixtures.
3
3
 
4
- This gem allows you to 'freeze' your ActiveRecord models to Rails compatible fixture files. This allows you to store real data statically for quick start dev/staging evironments.
4
+ This gem allows you to 'freeze' your ActiveRecord models to create repeatable datasets for development.
5
5
 
6
6
  ## Installation
7
7
 
@@ -31,7 +31,7 @@ end
31
31
 
32
32
  Create an initializer and set the path for fixtures to be saved
33
33
 
34
- `Freezer::Base.fixture_path = Rails.root.join("test", "fixtures")`
34
+ `Freezer::Base.fixture_path = Rails.root.join("db", "seeds")`
35
35
 
36
36
  ### Define Freezers
37
37
 
@@ -49,6 +49,26 @@ class PostFreezer < DeepFreezer::Base
49
49
  end
50
50
  ```
51
51
 
52
+ #### Overriding Attributes
53
+
54
+ Attributes can be overrode at time of freeze, similar to ActiveModel Serializers, by defining a method with the same name as the attribute name.
55
+
56
+ ```
57
+ class PostFreezer < DeepFreezer::Base
58
+
59
+ freeze :id,
60
+ :title,
61
+ :body,
62
+ :created_at,
63
+ :updated_at
64
+
65
+ def title
66
+ "Frozen Title"
67
+ end
68
+
69
+ end
70
+ ```
71
+
52
72
  ### Perform Freeze
53
73
 
54
74
  And then write a script to select and freeze the records you want:
@@ -58,7 +78,7 @@ And then write a script to select and freeze the records you want:
58
78
  posts.map { |p | PostFreezer.new(p).freeze }
59
79
  ```
60
80
 
61
- This will result in a `posts.yml` file in `test/fixtures` which can be loaded by running `rake db:fixtures:load`
81
+ This will result in a `posts.yml` file in `db/seeds` which can be loaded by adding `DeepFreezer::Defrost.load!` to your `seeds.rb` file.
62
82
 
63
83
  ### Reset Fixtures
64
84
 
@@ -30,7 +30,11 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
+ spec.add_dependency "activerecord", "> 4.2.10", "< 6.0.0"
34
+
33
35
  spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "pry"
34
37
  spec.add_development_dependency "rake", "~> 10.0"
35
38
  spec.add_development_dependency "rspec", "~> 3.0"
39
+ spec.add_development_dependency "activerecord-nulldb-adapter"
36
40
  end
@@ -3,5 +3,4 @@ require "deep_freezer/base"
3
3
  require "deep_freezer/defrost"
4
4
 
5
5
  module DeepFreezer
6
- # Your code goes here...
7
6
  end
@@ -26,7 +26,7 @@ class DeepFreezer::Base
26
26
  end
27
27
  end
28
28
 
29
- yaml = ({ "#{freezable.class.to_s.tableize}_#{freezable.id.to_s}" => freezable.attributes }.to_yaml).gsub("---", "")
29
+ yaml = ([{ "#{freezable.class.to_s}" => freezable.attributes }].to_yaml).gsub("---", "")
30
30
 
31
31
  write_to_file yaml, freezable.class.to_s.tableize
32
32
  end
@@ -1,26 +1,28 @@
1
1
  class DeepFreezer::Defrost
2
2
 
3
3
  def self.load!
4
-
5
4
  path = DeepFreezer::Base.fixture_path.join("**/*.yml")
6
5
  Dir.glob(path).each do |file|
7
6
  objects = YAML.load(File.read(file))
8
7
  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)
8
+ objects.each do |object|
9
+ instance = self.hash_to_instance(object)
10
+ sql = self.sql_for(instance)
20
11
  ActiveRecord::Base.connection.execute sql
21
12
  end
22
13
  end
14
+ end
15
+
16
+ def self.hash_to_instance(object)
17
+ klass = object.keys.first
18
+ attrs = object[klass]
19
+ instance = klass.constantize.new
23
20
 
21
+ attrs.keys.each do |a|
22
+ instance.send("#{a}=", attrs[a])
23
+ end
24
+
25
+ instance
24
26
  end
25
27
 
26
28
  def self.sql_for(record)
@@ -1,3 +1,3 @@
1
1
  module DeepFreezer
2
- VERSION = "0.4.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_freezer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Provan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.10
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: 4.2.10
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.0
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: bundler
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +44,20 @@ dependencies:
24
44
  - - "~>"
25
45
  - !ruby/object:Gem::Version
26
46
  version: '1.16'
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
27
61
  - !ruby/object:Gem::Dependency
28
62
  name: rake
29
63
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +86,20 @@ dependencies:
52
86
  - - "~>"
53
87
  - !ruby/object:Gem::Version
54
88
  version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: activerecord-nulldb-adapter
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
55
103
  description: This gem allows you to 'freeze' your ActiveRecord models to Rails compatible
56
104
  fixture files. This allows you to store real data statically for quick start dev/staging
57
105
  evironments.