bridgetown-activerecord 2.0.0 → 2.1.0
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 -5
- data/bridgetown.automation.rb +12 -13
- data/lib/bridgetown-activerecord/initializer.rb +2 -1
- data/lib/bridgetown-activerecord/version.rb +1 -1
- data/lib/tasks/database.rake +2 -2
- 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: ef8ced2ced4ceb5c4945477bb4ff888effd806d532b923f08524963210f211dd
|
4
|
+
data.tar.gz: 9945be6d6dc6c7d11089ae5d227102d23f5f61c92d10d2891fbb45da12a6b4ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55d827960c968db59a1477dc39945c54c6f6f55a9d040da866f30295e9902563b64325fb29eae2a3e69a656fa5913534a75daaebff11daf69f91445b2a07afd0
|
7
|
+
data.tar.gz: 072241e0d27f71b085c5a9f54cfeae05c7a0ef34f4ad4e0bc74207579dbd6deb343cbded7edea844eeedc8901bd57032b60dae11dd7eaff1364edf2435ae48f1
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
# Bridgetown
|
1
|
+
# Bridgetown Active Record plugin
|
2
2
|
|
3
|
-
|
3
|
+
This plugin adds Active Record support to Bridgetown sites (v1.2 or higher). You can pull data from a database (currently PostgreSQL is officially supported) during a static build or during server requests (or both!) and use many of the features you know and love from Active Record in Rails—including migrations!
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
> **IMPORTANT NOTE:** there's currently a compatibilty issue between Rails 7 gems and Rack version 3. For now, please add `gem "rack", "~> 2.2"` to your Gemfile _before_ you install this plugin.
|
8
|
+
|
9
|
+
It's recommended you run our automation script to set up your project to support Active Record and DB models:
|
8
10
|
|
9
11
|
```shell
|
10
12
|
$ bin/bridgetown apply https://github.com/bridgetownrb/bridgetown-activerecord
|
@@ -13,7 +15,7 @@ $ bin/bridgetown apply https://github.com/bridgetownrb/bridgetown-activerecord
|
|
13
15
|
Or for a fully manual setup:
|
14
16
|
|
15
17
|
```shell
|
16
|
-
$ bundle add bridgetown-activerecord
|
18
|
+
$ bundle add bridgetown-activerecord
|
17
19
|
```
|
18
20
|
|
19
21
|
then replicate the individual steps outlined in the [automation script](https://github.com/bridgetownrb/bridgetown-activerecord/blob/main/bridgetown.automation.rb).
|
@@ -24,6 +26,8 @@ You will need to decide on your database adapter of choice. For a typical Postgr
|
|
24
26
|
$ bundle add pg
|
25
27
|
```
|
26
28
|
|
29
|
+
When deploying to production, the `DATABASE_URL` ENV var will need to be set with the appropriate connection string…many hosting services will do this for you automatically.
|
30
|
+
|
27
31
|
## Usage
|
28
32
|
|
29
33
|
Let's create a simple Movie model to load and save our favorite movies. Add the file `models/movie.rb`:
|
@@ -92,7 +96,18 @@ $ bin/bridgetown console
|
|
92
96
|
}
|
93
97
|
```
|
94
98
|
|
95
|
-
You're ready to roll to take full advantage of
|
99
|
+
You're ready to roll to take full advantage of Active Record database models in your Bridgetown site!
|
100
|
+
|
101
|
+
## Changing the Models Directory
|
102
|
+
|
103
|
+
If you'd prefer to set up your models folder elsewhere other than `./models`, you can move the files to another path and then update your Rakefile to pass in that path. For example, you could use the more familiar `app/models`:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
require "bridgetown-activerecord"
|
107
|
+
BridgetownActiveRecord.load_tasks(models_dir: "app/models")
|
108
|
+
```
|
109
|
+
|
110
|
+
(Don't forget to update your autoload path in `config/initializers.rb` accordingly.)
|
96
111
|
|
97
112
|
## Testing
|
98
113
|
|
data/bridgetown.automation.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
add_gem "bridgetown-activerecord"
|
2
|
+
add_gem "annotate", group: :development
|
3
3
|
|
4
4
|
# TODO:
|
5
5
|
#dboptions = ["postgresql", "mysql", "vanilla"]
|
@@ -50,21 +50,20 @@ create_file ".standalone_migrations" do
|
|
50
50
|
YML
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
<<~YML
|
53
|
+
insert_into_file "Rakefile", "require \"bridgetown-activerecord\"\nBridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
ruby_configure "Support for autoloading models" do
|
56
|
+
<<~RUBY
|
57
|
+
config.autoload_paths << {
|
58
|
+
path: "models",
|
59
|
+
eager: true
|
60
|
+
}
|
59
61
|
|
60
|
-
autoloader_collapsed_paths
|
61
|
-
|
62
|
-
YML
|
62
|
+
config.autoloader_collapsed_paths << "models/concerns"
|
63
|
+
RUBY
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
# TODO: add to initializer !!!
|
66
|
+
add_initializer :"bridgetown-activerecord"
|
68
67
|
|
69
68
|
say_status :active_record, "The plugin has been configured. For usage help visit:"
|
70
69
|
say_status :active_record, "https://github.com/bridgetownrb/bridgetown-activerecord/blob/main/README.md"
|
@@ -6,7 +6,8 @@ require "active_record"
|
|
6
6
|
require "active_support/configuration_file"
|
7
7
|
|
8
8
|
module BridgetownActiveRecord
|
9
|
-
def self.load_tasks
|
9
|
+
def self.load_tasks(models_dir: "models")
|
10
|
+
ENV["BRIDGETOWN_ACTIVERECORD_MODELS_DIR"] ||= models_dir
|
10
11
|
load File.expand_path("../tasks/database.rake", __dir__)
|
11
12
|
end
|
12
13
|
|
data/lib/tasks/database.rake
CHANGED
@@ -5,12 +5,12 @@ ENV["SCHEMA"] = File.join(Dir.pwd, "db", "schema.rb")
|
|
5
5
|
require "standalone_migrations"
|
6
6
|
StandaloneMigrations::Tasks.load_tasks
|
7
7
|
|
8
|
-
require "
|
8
|
+
require "./#{ENV.fetch("BRIDGETOWN_ACTIVERECORD_MODELS_DIR", "models")}/application_record"
|
9
9
|
|
10
10
|
# Setup Annotate so it runs on db:migrate, etc.
|
11
11
|
if Bridgetown.environment.development?
|
12
12
|
require "annotate"
|
13
|
-
ENV["model_dir"] = "models"
|
13
|
+
ENV["model_dir"] = ENV.fetch("BRIDGETOWN_ACTIVERECORD_MODELS_DIR", "models")
|
14
14
|
Annotate::Helpers.class_eval do
|
15
15
|
# We need to redefine this because our custom model_dir shortcircuits the migration task enhancement
|
16
16
|
def self.include_models?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bridgetown
|