static_db 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -15
- data/lib/static_db/dump.rb +3 -5
- data/lib/static_db/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57ead27ee0cc81c76fcb1f83c2b279819f3680895a59ab3e4dfcb80e26dad472
|
|
4
|
+
data.tar.gz: ac0d29ebfcc4a433f47b3e7e636e239937e2b41ecd905aabc280d045dd173ab8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b070a834bc54a708fa340a65645160d36612774eabbd712893e9875e2e45e7ade87e40632f51f5e9eb489dc6b4cf8230b85a1f43ad0b46f05693de596db69cd6
|
|
7
|
+
data.tar.gz: 9dbb730c2a93af6ac1d8f70e0ea277ddb7394e4ccbdefe6f6a2278d3bbf4c877c2798e53f5a04dccede9a2ea941e0e109f2ccb32fbcaa953bbf28b6a02f49434
|
data/README.md
CHANGED
|
@@ -4,36 +4,41 @@
|
|
|
4
4
|
|
|
5
5
|
# static_db
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Dump DB contents to YAML and load them back again. Aimed at SQLite. Committable to git.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
WARNING: This gem modifies the Rails startup sequence. Don't use this gem unless you want to build a static site generator. This gem also creates and drops the DB for you.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
# my-cool-gem.gemspec
|
|
15
|
-
Gem::Specification.new do |spec|
|
|
16
|
-
# ...
|
|
17
|
-
spec.add_dependency "static_db"
|
|
18
|
-
# ...
|
|
19
|
-
end
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Or adding to your project:
|
|
13
|
+
Add it to your Rails project:
|
|
23
14
|
|
|
24
15
|
```ruby
|
|
25
16
|
# Gemfile
|
|
26
17
|
gem "static_db"
|
|
18
|
+
|
|
19
|
+
# config/initializer/static_db.rb
|
|
20
|
+
StaticDb.configure do |config|
|
|
21
|
+
# `content/data` is the default. You only need this initializer,
|
|
22
|
+
# if you want a custom path.
|
|
23
|
+
config.fixture_path = Rails.root.join("content", "data")
|
|
24
|
+
end
|
|
27
25
|
```
|
|
28
26
|
|
|
29
27
|
### Supported Ruby versions
|
|
30
28
|
|
|
31
|
-
- Ruby (MRI) >= 2.
|
|
32
|
-
- JRuby >= 9.3.0
|
|
29
|
+
- Ruby (MRI) >= 3.2.0
|
|
33
30
|
|
|
34
31
|
## Usage
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
Only use on Rails projects with SQLite. Have a valid `db/schema.rb`. For additional dramatic effect, do a `rails db:drop`.
|
|
34
|
+
|
|
35
|
+
Start your app with `bin/dev`. You will notice that a DB gets created for you. It will be empty.
|
|
36
|
+
|
|
37
|
+
Create some records. Then, stop your server with Ctrl+C.
|
|
38
|
+
|
|
39
|
+
The DB contents will have been dumped to `content/data`. Your SQLite DB will be gone.
|
|
40
|
+
|
|
41
|
+
Restart your server with `bin/dev`. Your SQLite DB will be back and populated with all previously stored data, recreated from `content/data`.
|
|
37
42
|
|
|
38
43
|
## Contributing
|
|
39
44
|
|
data/lib/static_db/dump.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module StaticDb
|
|
4
4
|
class Dump
|
|
5
5
|
|
|
6
|
-
attr_reader :fixture_path
|
|
6
|
+
attr_reader :fixture_path, :models_to_be_saved
|
|
7
7
|
|
|
8
8
|
def initialize(fixture_path:)
|
|
9
9
|
@fixture_path = Pathname.new(fixture_path)
|
|
@@ -37,9 +37,7 @@ module StaticDb
|
|
|
37
37
|
|
|
38
38
|
errors = []
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
next if model.abstract_class?
|
|
42
|
-
|
|
40
|
+
models_to_be_saved.each do |model|
|
|
43
41
|
model.find_each do |record|
|
|
44
42
|
unless record.valid?
|
|
45
43
|
errors << { model: model.name, slug: record.slug, errors: record.errors.full_messages }
|
|
@@ -65,7 +63,7 @@ module StaticDb
|
|
|
65
63
|
|
|
66
64
|
def dump_fixtures!
|
|
67
65
|
reset_data_directory!
|
|
68
|
-
|
|
66
|
+
models_to_be_saved.each { |model| format_and_write_yaml_file!(model) }
|
|
69
67
|
end
|
|
70
68
|
|
|
71
69
|
def reset_data_directory!
|
data/lib/static_db/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: static_db
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Klaus Weidinger
|
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
120
|
- !ruby/object:Gem::Version
|
|
121
121
|
version: '0'
|
|
122
122
|
requirements: []
|
|
123
|
-
rubygems_version:
|
|
123
|
+
rubygems_version: 4.0.8
|
|
124
124
|
specification_version: 4
|
|
125
125
|
summary: Example description
|
|
126
126
|
test_files: []
|