bridgetown-activerecord 1.0.0 → 2.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
  SHA256:
3
- metadata.gz: 86121e3d1de53dc4a6cb5af343f14532e57052ccd3fc2e86c8e87996d6325a72
4
- data.tar.gz: a95b95bd75f2832c103f1595b4f4faaa54fd4b0dbad3a751c87026dbb0091027
3
+ metadata.gz: ccfd8d0b6032758ade7b72ece8ff373552c3257d84a35cab4a34e98c88789fb3
4
+ data.tar.gz: 244806f70399573021e39162d2aca78e634a8e41279c3e23c85cf42f8d1fa176
5
5
  SHA512:
6
- metadata.gz: 6c60311f9a4b459010156dd772f4b7515ddb9ce91aa10168faddd31cb349950918c86df428e1db694531dba263b6263ec1e69bc12aa7aae14fe450268f5ca97e
7
- data.tar.gz: 95f8564b8a9f4fc36a0a85bd75d7f57d59e66de6a951a1c9f0bb3c5f5f549e186e66397b5c0aa50f00753b706ab195973268de0bc459e230e26f9e4bd818c816
6
+ metadata.gz: db2527fb6c3ca7da3f67678bbb75d845a01d310ab762ec05661b688650a19b203c400bbfd8de4c1c86f2fdbd143e8383cda37142a751904c27368ea04612a17b
7
+ data.tar.gz: fea781ad77051b5018687ba9199a40839bbfc00926810170942309cdb0c5ec5e772589214d31b04731778d57aa25e8430e9518b51c2f3766b05de652c7b78af6
data/CHANGELOG.md CHANGED
@@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
- - ...
10
+ ## [2.0.0] - 2022-10-08
11
11
 
12
- ## 0.1.0 - YYYY-MM-DD
12
+ - Upgrade to initializers system in Bridgetown 1.2
13
+
14
+ ## 1.0.0 - 2022-04-11
13
15
 
14
16
  - First version
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Bridgetown ActiveRecord plugin
2
2
 
3
+ **NOTE:** currently waiting on a bugfix in Bridgetown itself before getting the green light…coming very soon!
4
+
3
5
  ## Installation
4
6
 
5
7
  It's recommended you run our automation script to set up your project to support ActiveRecord and DB models:
@@ -24,7 +26,73 @@ $ bundle add pg
24
26
 
25
27
  ## Usage
26
28
 
27
- TBC
29
+ Let's create a simple Movie model to load and save our favorite movies. Add the file `models/movie.rb`:
30
+
31
+ ```rb
32
+ class Movie < ApplicationRecord
33
+ validates :title, presence: true, uniqueness: { case_insensitive: true }
34
+
35
+ def uppercase_title
36
+ title.upcase
37
+ end
38
+ end
39
+ ```
40
+
41
+ Then add a new migration for the Movie model.
42
+
43
+ ```sh
44
+ $ bin/bridgetown db:new_migration name=create_movies
45
+ ```
46
+
47
+ That will create a new migration file in `db/migrate`. Edit the file so it looks like this:
48
+
49
+ ```ruby
50
+ class CreateMovies < ActiveRecord::Migration[7.0]
51
+ def change
52
+ create_table :movies do |t|
53
+ t.string :title, null: false
54
+ t.string :director
55
+ t.integer :year
56
+
57
+ t.timestamps
58
+ end
59
+ end
60
+ end
61
+ ```
62
+
63
+ Awesome, now let's create the database and run the migration!
64
+
65
+ ```sh
66
+ $ bin/bridgetown db:create
67
+ $ bin/bridgetown db:migrate
68
+ ```
69
+
70
+ If all goes well, the database should be created, the migration run, a new `db/schema.rb` saved, and schema annotations added to the top of `models/movie.rb`!
71
+
72
+ Let's try it out in the Bridgetown console.
73
+
74
+ ```sh
75
+ $ bin/bridgetown console
76
+ ```
77
+
78
+ ```ruby
79
+ > Movie.count
80
+ 0
81
+ > Movie.create(title: "Free Guy", director: "Shawn Levy", year: "2021")
82
+ > Movie.count
83
+ 1
84
+ > Movie.last
85
+ #<Movie:0x0000000109e26378> {
86
+ :id => 1,
87
+ :title => "Free Guy",
88
+ :director => "Shawn Levy",
89
+ :year => 2021,
90
+ :created_at => 2022-03-12 23:24:28.98137 UTC,
91
+ :updated_at => 2022-03-12 23:24:28.98137 UTC
92
+ }
93
+ ```
94
+
95
+ You're ready to roll to take full advantage of ActiveRecord database models in your Bridgetown site!
28
96
 
29
97
  ## Testing
30
98
 
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.required_ruby_version = ">= 2.7.0"
19
19
 
20
- spec.add_dependency "bridgetown", ">= 1.0", "< 2.0"
20
+ spec.add_dependency "bridgetown", ">= 1.2.0.beta2", "< 2.0"
21
21
  spec.add_dependency "activerecord", "~> 7.0"
22
22
  spec.add_dependency "standalone_migrations", "~> 7.0"
23
23
 
@@ -62,7 +62,9 @@ append_to_file "bridgetown.config.yml" do
62
62
  YML
63
63
  end
64
64
 
65
- insert_into_file "Rakefile", "BridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
65
+ insert_into_file "Rakefile", "require \"bridgetown-activerecord\"\nBridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
66
+
67
+ # TODO: add to initializer !!!
66
68
 
67
69
  say_status :active_record, "The plugin has been configured. For usage help visit:"
68
70
  say_status :active_record, "https://github.com/bridgetownrb/bridgetown-activerecord/blob/main/README.md"
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV["RAILS_ENV"] = Bridgetown.environment
4
+
5
+ require "active_record"
6
+ require "active_support/configuration_file"
7
+
8
+ module BridgetownActiveRecord
9
+ def self.load_tasks
10
+ load File.expand_path("../tasks/database.rake", __dir__)
11
+ end
12
+
13
+ def self.db_configuration(config)
14
+ ActiveSupport::ConfigurationFile.parse(File.join(config.root_dir, "config", "database.yml"))
15
+ end
16
+
17
+ def self.log_writer
18
+ Bridgetown::LogWriter.new.tap(&:enable_prefix)
19
+ end
20
+ end
21
+
22
+ Bridgetown.initializer :"bridgetown-activerecord" do |config|
23
+ ActiveRecord::Base.establish_connection(
24
+ BridgetownActiveRecord.db_configuration(config)[Bridgetown.environment]
25
+ )
26
+ ActiveRecord::Base.logger = BridgetownActiveRecord.log_writer
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgetownActiveRecord
4
- VERSION = "1.0.0"
4
+ VERSION = "2.0.0"
5
5
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bridgetown"
4
- require "bridgetown-activerecord/builder"
4
+ require "bridgetown-activerecord/initializer"
@@ -5,14 +5,17 @@ ENV["SCHEMA"] = File.join(Dir.pwd, "db", "schema.rb")
5
5
  require "standalone_migrations"
6
6
  StandaloneMigrations::Tasks.load_tasks
7
7
 
8
- # Setup Annotate so it runs on db:migrate, etc.
9
- require "annotate"
10
8
  require "./models/application_record"
11
- ENV["model_dir"] = "models"
12
- Annotate::Helpers.class_eval do
13
- # We need to redefine this because our custom model_dir shortcircuits the migration task enhancement
14
- def self.include_models?
15
- true
9
+
10
+ # Setup Annotate so it runs on db:migrate, etc.
11
+ if Bridgetown.environment.development?
12
+ require "annotate"
13
+ ENV["model_dir"] = "models"
14
+ Annotate::Helpers.class_eval do
15
+ # We need to redefine this because our custom model_dir shortcircuits the migration task enhancement
16
+ def self.include_models?
17
+ true
18
+ end
16
19
  end
20
+ Annotate.load_tasks
17
21
  end
18
- Annotate.load_tasks
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: 1.0.0
4
+ version: 2.0.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-04-10 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridgetown
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: 1.2.0.beta2
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: 1.2.0.beta2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
@@ -116,7 +116,7 @@ files:
116
116
  - bridgetown-activerecord.gemspec
117
117
  - bridgetown.automation.rb
118
118
  - lib/bridgetown-activerecord.rb
119
- - lib/bridgetown-activerecord/builder.rb
119
+ - lib/bridgetown-activerecord/initializer.rb
120
120
  - lib/bridgetown-activerecord/version.rb
121
121
  - lib/tasks/database.rake
122
122
  homepage: https://github.com/bridgetownrb/bridgetown-activerecord
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ENV["RAILS_ENV"] = Bridgetown.environment
4
-
5
- require "active_record"
6
- require "active_support/configuration_file"
7
-
8
- module BridgetownActiveRecord
9
- def self.load_tasks
10
- load File.expand_path("../tasks/database.rake", __dir__)
11
- end
12
-
13
- class Builder < Bridgetown::Builder
14
- def self.db_configuration(site)
15
- ActiveSupport::ConfigurationFile.parse(site.in_root_dir("config", "database.yml"))
16
- end
17
-
18
- def self.log_writer
19
- Bridgetown::LogWriter.new.tap(&:enable_prefix)
20
- end
21
-
22
- Bridgetown::Hooks.register_one :site, :after_init, reloadable: false do |site|
23
- ActiveRecord::Base.establish_connection db_configuration(site)[Bridgetown.environment]
24
- ActiveRecord::Base.logger = log_writer
25
- end
26
-
27
- # no-op
28
- def build; end
29
- end
30
- end
31
-
32
- BridgetownActiveRecord::Builder.register