bridgetown-activerecord 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 86121e3d1de53dc4a6cb5af343f14532e57052ccd3fc2e86c8e87996d6325a72
4
+ data.tar.gz: a95b95bd75f2832c103f1595b4f4faaa54fd4b0dbad3a751c87026dbb0091027
5
+ SHA512:
6
+ metadata.gz: 6c60311f9a4b459010156dd772f4b7515ddb9ce91aa10168faddd31cb349950918c86df428e1db694531dba263b6263ec1e69bc12aa7aae14fe450268f5ca97e
7
+ data.tar.gz: 95f8564b8a9f4fc36a0a85bd75d7f57d59e66de6a951a1c9f0bb3c5f5f549e186e66397b5c0aa50f00753b706ab195973268de0bc459e230e26f9e4bd818c816
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ /vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ Gemfile.lock
18
+ .bundle
19
+ .ruby-version
20
+
21
+ # Node
22
+ node_modules
23
+ .npm
24
+ .node_repl_history
25
+
26
+ # Yarn
27
+ yarn-error.log
28
+ yarn-debug.log*
29
+ .pnp/
30
+ .pnp.js
31
+
32
+ # Yarn Integrity file
33
+ .yarn-integrity
34
+
35
+ test/dest
36
+ .bridgetown-metadata
37
+ .bridgetown-cache
38
+ .bridgetown-webpack
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require: rubocop-bridgetown
2
+
3
+ inherit_gem:
4
+ rubocop-bridgetown: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.5
8
+
9
+ Exclude:
10
+ - .gitignore
11
+ - .rubocop.yml
12
+ - "*.gemspec"
13
+
14
+ - Gemfile.lock
15
+ - CHANGELOG.md
16
+ - LICENSE.txt
17
+ - README.md
18
+ - Rakefile
19
+ - bridgetown.automation.rb
20
+ - lib/tasks/database.rake
21
+
22
+ - script/**/*
23
+ - vendor/**/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## Unreleased
9
+
10
+ - ...
11
+
12
+ ## 0.1.0 - YYYY-MM-DD
13
+
14
+ - First version
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "bridgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
7
+
8
+ group :test do
9
+ gem "minitest"
10
+ gem "minitest-reporters"
11
+ gem "shoulda"
12
+ end
13
+
14
+ gem "pg", "~> 1.3", group: :test
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022-present Jared White and Bridgetown Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Bridgetown ActiveRecord plugin
2
+
3
+ ## Installation
4
+
5
+ It's recommended you run our automation script to set up your project to support ActiveRecord and DB models:
6
+
7
+ ```shell
8
+ $ bin/bridgetown apply https://github.com/bridgetownrb/bridgetown-activerecord
9
+ ```
10
+
11
+ Or for a fully manual setup:
12
+
13
+ ```shell
14
+ $ bundle add bridgetown-activerecord -g bridgetown_plugins
15
+ ```
16
+
17
+ then replicate the individual steps outlined in the [automation script](https://github.com/bridgetownrb/bridgetown-activerecord/blob/main/bridgetown.automation.rb).
18
+
19
+ You will need to decide on your database adapter of choice. For a typical PostgreSQL configuration, add the `pg` gem.
20
+
21
+ ```shell
22
+ $ bundle add pg
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ TBC
28
+
29
+ ## Testing
30
+
31
+ * Run `bundle exec rake test` to run the test suite
32
+ * Or run `script/cibuild` to validate with Rubocop and Minitest together.
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it (https://github.com/bridgetownrb/bridgetown-activerecord/fork)
37
+ 2. Clone the fork using `git clone` to your local development machine.
38
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 5. Push to the branch (`git push origin my-new-feature`)
41
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ t.warning = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bridgetown-activerecord/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridgetown-activerecord"
7
+ spec.version = BridgetownActiveRecord::VERSION
8
+ spec.author = "Bridgetown Team"
9
+ spec.email = "maintainers@bridgetownrb.com"
10
+ spec.summary = "Plugin to add ActiveRecord support to Bridgetown sites"
11
+ spec.homepage = "https://github.com/bridgetownrb/bridgetown-activerecord"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
15
+ spec.test_files = spec.files.grep(%r!^test/!)
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.required_ruby_version = ">= 2.7.0"
19
+
20
+ spec.add_dependency "bridgetown", ">= 1.0", "< 2.0"
21
+ spec.add_dependency "activerecord", "~> 7.0"
22
+ spec.add_dependency "standalone_migrations", "~> 7.0"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake", ">= 13.0"
26
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.3"
27
+ end
@@ -0,0 +1,71 @@
1
+ add_bridgetown_plugin "bridgetown-activerecord"
2
+ run "bundle add annotate -g development", abort_on_failure: false
3
+
4
+ # TODO:
5
+ #dboptions = ["postgresql", "mysql", "vanilla"]
6
+ #dbadapter = ask("Which adapter should be used for your database?", limited_to: dboptions)
7
+
8
+ dbadapter = "postgresql"
9
+ dbprefix = ask("What identifier should be used for your database prefix?", default: "bt_demo")
10
+
11
+ # TODO: use Rails DB templates
12
+ #rails_db_tmpl_url = "https://github.com/rails/rails/blob/7-0-stable/railties/lib/rails/generators/rails/app/templates/config/databases/"
13
+
14
+ create_file "config/database.yml" do
15
+ <<~YML
16
+ default: &default
17
+ adapter: #{dbadapter}
18
+ encoding: unicode
19
+ pool: 5
20
+
21
+ development:
22
+ <<: *default
23
+ database: #{dbprefix}_development
24
+
25
+ test: &test
26
+ <<: *default
27
+ database: #{dbprefix}_test
28
+
29
+ production:
30
+ <<: *default
31
+ url: <%= ENV['DATABASE_URL'] %>
32
+ database: #{dbprefix}_production
33
+ YML
34
+ end
35
+
36
+ create_file "models/application_record.rb" do
37
+ <<~RUBY
38
+ require "active_record"
39
+
40
+ class ApplicationRecord < ActiveRecord::Base
41
+ primary_abstract_class
42
+ end
43
+ RUBY
44
+ end
45
+
46
+ create_file ".standalone_migrations" do
47
+ <<~YML
48
+ config:
49
+ database: config/database.yml
50
+ YML
51
+ end
52
+
53
+ append_to_file "bridgetown.config.yml" do
54
+ <<~YML
55
+
56
+ autoload_paths:
57
+ - path: models
58
+ eager: true
59
+
60
+ autoloader_collapsed_paths:
61
+ - models/concerns
62
+ YML
63
+ end
64
+
65
+ insert_into_file "Rakefile", "BridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
66
+
67
+ say_status :active_record, "The plugin has been configured. For usage help visit:"
68
+ say_status :active_record, "https://github.com/bridgetownrb/bridgetown-activerecord/blob/main/README.md"
69
+
70
+ say_status :active_record, "Don't forget to add a specific database adapter to your Gemfile! For example:"
71
+ say_status :active_record, "$ bundle add pg".bold
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownActiveRecord
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "bridgetown-activerecord/builder"
@@ -0,0 +1,18 @@
1
+ # Setup ActiveRecord tasks like db:migrate, etc.
2
+ # Also see .standalone_migrations config file in project root
3
+ ENV["RAILS_ENV"] = Bridgetown.environment
4
+ ENV["SCHEMA"] = File.join(Dir.pwd, "db", "schema.rb")
5
+ require "standalone_migrations"
6
+ StandaloneMigrations::Tasks.load_tasks
7
+
8
+ # Setup Annotate so it runs on db:migrate, etc.
9
+ require "annotate"
10
+ 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
16
+ end
17
+ end
18
+ Annotate.load_tasks
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgetown-activerecord
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bridgetown Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bridgetown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '7.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '7.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: standalone_migrations
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '7.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '7.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '13.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop-bridgetown
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.3'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.3'
103
+ description:
104
+ email: maintainers@bridgetownrb.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - ".rubocop.yml"
111
+ - CHANGELOG.md
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - bridgetown-activerecord.gemspec
117
+ - bridgetown.automation.rb
118
+ - lib/bridgetown-activerecord.rb
119
+ - lib/bridgetown-activerecord/builder.rb
120
+ - lib/bridgetown-activerecord/version.rb
121
+ - lib/tasks/database.rake
122
+ homepage: https://github.com/bridgetownrb/bridgetown-activerecord
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 2.7.0
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.3.3
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Plugin to add ActiveRecord support to Bridgetown sites
145
+ test_files: []