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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 479d7410cc5f976ed22e42d910e249055c741df4e4c6cdf8267b01bea16f8217
4
- data.tar.gz: 7b9e03429fa960d457e60a49055eacdabdd55d987e73243a8beb56d72f7437de
3
+ metadata.gz: 57ead27ee0cc81c76fcb1f83c2b279819f3680895a59ab3e4dfcb80e26dad472
4
+ data.tar.gz: ac0d29ebfcc4a433f47b3e7e636e239937e2b41ecd905aabc280d045dd173ab8
5
5
  SHA512:
6
- metadata.gz: 0e6ef11395d226a4c53bd953ca08c103509dae4c85330c797b7620b28360366815e32942a2284430be8437220f6433766a0ed0206582b56d823e80779cc00bde
7
- data.tar.gz: d7bef38d14c21fcbbbf321756ec4d9319b90ef7d45ccd408de7bc80c596eb4c88f0a83b98b0f4b92e9fa0875973d45086b57745ea2a2782196001e3300f12a1e
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
- TBD
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
- Adding to a gem:
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
- ```ruby
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.7.0
32
- - JRuby >= 9.3.0
29
+ - Ruby (MRI) >= 3.2.0
33
30
 
34
31
  ## Usage
35
32
 
36
- TBD
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
 
@@ -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
- ActiveRecord::Base.descendants.each do |model|
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
- @models_to_be_saved.each { |model| format_and_write_yaml_file!(model) }
66
+ models_to_be_saved.each { |model| format_and_write_yaml_file!(model) }
69
67
  end
70
68
 
71
69
  def reset_data_directory!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StaticDb # :nodoc:
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
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.2
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: 3.6.7
123
+ rubygems_version: 4.0.8
124
124
  specification_version: 4
125
125
  summary: Example description
126
126
  test_files: []