bridgetown-activerecord 2.0.0 → 2.1.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
  SHA256:
3
- metadata.gz: ccfd8d0b6032758ade7b72ece8ff373552c3257d84a35cab4a34e98c88789fb3
4
- data.tar.gz: 244806f70399573021e39162d2aca78e634a8e41279c3e23c85cf42f8d1fa176
3
+ metadata.gz: ef8ced2ced4ceb5c4945477bb4ff888effd806d532b923f08524963210f211dd
4
+ data.tar.gz: 9945be6d6dc6c7d11089ae5d227102d23f5f61c92d10d2891fbb45da12a6b4ed
5
5
  SHA512:
6
- metadata.gz: db2527fb6c3ca7da3f67678bbb75d845a01d310ab762ec05661b688650a19b203c400bbfd8de4c1c86f2fdbd143e8383cda37142a751904c27368ea04612a17b
7
- data.tar.gz: fea781ad77051b5018687ba9199a40839bbfc00926810170942309cdb0c5ec5e772589214d31b04731778d57aa25e8430e9518b51c2f3766b05de652c7b78af6
6
+ metadata.gz: 55d827960c968db59a1477dc39945c54c6f6f55a9d040da866f30295e9902563b64325fb29eae2a3e69a656fa5913534a75daaebff11daf69f91445b2a07afd0
7
+ data.tar.gz: 072241e0d27f71b085c5a9f54cfeae05c7a0ef34f4ad4e0bc74207579dbd6deb343cbded7edea844eeedc8901bd57032b60dae11dd7eaff1364edf2435ae48f1
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
- # Bridgetown ActiveRecord plugin
1
+ # Bridgetown Active Record plugin
2
2
 
3
- **NOTE:** currently waiting on a bugfix in Bridgetown itself before getting the green light…coming very soon!
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
- It's recommended you run our automation script to set up your project to support ActiveRecord and DB models:
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 -g bridgetown_plugins
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 ActiveRecord database models in your Bridgetown site!
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
 
@@ -1,5 +1,5 @@
1
- add_bridgetown_plugin "bridgetown-activerecord"
2
- run "bundle add annotate -g development", abort_on_failure: false
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
- append_to_file "bridgetown.config.yml" do
54
- <<~YML
53
+ insert_into_file "Rakefile", "require \"bridgetown-activerecord\"\nBridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
55
54
 
56
- autoload_paths:
57
- - path: models
58
- eager: true
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
- - models/concerns
62
- YML
62
+ config.autoloader_collapsed_paths << "models/concerns"
63
+ RUBY
63
64
  end
64
65
 
65
- insert_into_file "Rakefile", "require \"bridgetown-activerecord\"\nBridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgetownActiveRecord
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -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 "./models/application_record"
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.0.0
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-09 00:00:00.000000000 Z
11
+ date: 2022-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridgetown