rom-rails 2.2.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +30 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/ci.yml +67 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +30 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +17 -8
- data/README.md +10 -7
- data/db +1 -1
- data/docsite/source/index.html.md +165 -0
- data/lib/rom/rails/configuration.rb +4 -0
- data/lib/rom/rails/railtie.rb +17 -4
- data/lib/rom/rails/version.rb +1 -1
- data/log +1 -1
- data/rom-rails.gemspec +9 -3
- data/spec/dummy/config/initializers/rom.rb +1 -0
- data/spec/dummy/lib/namespaced_app/persistence/commands/create_additional_task.rb +11 -0
- data/spec/integration/initializer_spec.rb +6 -1
- metadata +27 -15
- data/.travis.yml +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aab84f6f3a0272e4e3745bace374ef628da306e77ab9c339b28bb320d8ff61dc
|
4
|
+
data.tar.gz: b2b0d450245b3405fad0b2cec2f513032f65fb294c2a47819cc2d503eb986de4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8432e4d4a4f9a9ed2c4da5ae7ba7e95d46d79e424796aedee2fda45fdd2c7b61a4f23203d03a848869e65fe665a8ed9736c8b031515b8103d23710291312dd3b
|
7
|
+
data.tar.gz: abe4967268a5f14621db4c24390c87bebdc1be02baaa1396d361e31c03863a3afd5295760d33697ad6c2dfc681aef02be90c509ad1dcd73f5763629b0ce9064f
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
name: "\U0001F41B Bug report"
|
3
|
+
about: See CONTRIBUTING.md for more information
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
11
|
+
|
12
|
+
For more information see [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md)
|
13
|
+
|
14
|
+
**Describe the bug**
|
15
|
+
|
16
|
+
A clear and concise description of what the bug is.
|
17
|
+
|
18
|
+
**To Reproduce**
|
19
|
+
|
20
|
+
Provide detailed steps to reproduce, an executable script would be best.
|
21
|
+
|
22
|
+
**Expected behavior**
|
23
|
+
|
24
|
+
A clear and concise description of what you expected to happen.
|
25
|
+
|
26
|
+
**Your environment**
|
27
|
+
|
28
|
+
- Affects my production application: **YES/NO**
|
29
|
+
- Ruby version: ...
|
30
|
+
- OS: ...
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
name: "\U0001F6E0 Feature request"
|
3
|
+
about: See CONTRIBUTING.md for more information
|
4
|
+
title: ''
|
5
|
+
labels: feature
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
Summary of what the feature is supposed to do.
|
11
|
+
|
12
|
+
## Examples
|
13
|
+
|
14
|
+
Code examples showing how the feature could be used.
|
15
|
+
|
16
|
+
## Resources
|
17
|
+
|
18
|
+
Additional information, like a link to the discussion forum thread where the feature was discussed etc.
|
@@ -0,0 +1,67 @@
|
|
1
|
+
---
|
2
|
+
name: ci
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
paths:
|
8
|
+
- ".github/workflows/ci.yml"
|
9
|
+
- lib/**
|
10
|
+
- "*.gemspec"
|
11
|
+
- spec/**
|
12
|
+
- db/migrate/**
|
13
|
+
- Rakefile
|
14
|
+
- Gemfile
|
15
|
+
- ".rubocop.yml"
|
16
|
+
pull_request:
|
17
|
+
branches:
|
18
|
+
- master
|
19
|
+
create:
|
20
|
+
jobs:
|
21
|
+
tests:
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
fail-fast: false
|
25
|
+
matrix:
|
26
|
+
ruby:
|
27
|
+
- '2.7'
|
28
|
+
- '2.6'
|
29
|
+
- '2.5'
|
30
|
+
- '2.4'
|
31
|
+
- 'jruby-9.3'
|
32
|
+
rails:
|
33
|
+
- "6.1.0"
|
34
|
+
- "6.0.0"
|
35
|
+
- "5.2.0"
|
36
|
+
- "5.1.0"
|
37
|
+
- "5.0.0"
|
38
|
+
- "4.2.0"
|
39
|
+
exclude:
|
40
|
+
- ruby: "2.4"
|
41
|
+
rails: "6.0.0"
|
42
|
+
- ruby: "2.4"
|
43
|
+
rails: "6.1.0"
|
44
|
+
- ruby: "2.7"
|
45
|
+
rails: "4.2.0"
|
46
|
+
env:
|
47
|
+
APT_DEPS: libsqlite3-dev
|
48
|
+
RAILS_VERSION: "${{matrix.rails}}"
|
49
|
+
RAILS_ENV: test
|
50
|
+
|
51
|
+
steps:
|
52
|
+
- name: Checkout
|
53
|
+
uses: actions/checkout@v1
|
54
|
+
- name: Install package dependencies
|
55
|
+
run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
|
56
|
+
- name: Set up Ruby
|
57
|
+
uses: ruby/setup-ruby@v1
|
58
|
+
with:
|
59
|
+
ruby-version: "${{matrix.ruby}}"
|
60
|
+
- name: Install latest bundler
|
61
|
+
run: |
|
62
|
+
gem install bundler --no-document
|
63
|
+
bundle config set without 'tools benchmarks docs'
|
64
|
+
- name: Bundle install
|
65
|
+
run: bundle install --jobs 4 --retry 3
|
66
|
+
- name: Run all tests
|
67
|
+
run: bundle exec rake app:db:reset app:spec
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# this file is managed by rom-rb/devtools project
|
2
|
+
|
3
|
+
name: docsite
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
paths:
|
8
|
+
- docsite/**
|
9
|
+
- .github/workflows/docsite.yml
|
10
|
+
branches:
|
11
|
+
- master
|
12
|
+
- release-**
|
13
|
+
tags:
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
update-docs:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v1
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: actions/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: "2.6.x"
|
24
|
+
- name: Install dependencies
|
25
|
+
run: |
|
26
|
+
gem install bundler
|
27
|
+
bundle install --jobs 4 --retry 3 --without benchmarks sql
|
28
|
+
- name: Symlink ossy
|
29
|
+
run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
|
30
|
+
- name: Trigger rom-rb.org deploy
|
31
|
+
env:
|
32
|
+
GITHUB_LOGIN: rom-bot
|
33
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
34
|
+
run: bin/ossy github workflow rom-rb/rom-rb.org ci
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# this file is managed by rom-rb/devtools project
|
2
|
+
|
3
|
+
name: sync_configs
|
4
|
+
|
5
|
+
on:
|
6
|
+
repository_dispatch:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
sync-configs:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
if: github.event.action == 'sync_configs'
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v1
|
14
|
+
- name: Update configuration files from devtools
|
15
|
+
env:
|
16
|
+
GITHUB_LOGIN: ${{ github.actor }}
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
18
|
+
run: |
|
19
|
+
git clone https://github.com/rom-rb/devtools.git tmp/devtools
|
20
|
+
|
21
|
+
rsync -av tmp/devtools/shared/ .
|
22
|
+
|
23
|
+
git config --local user.email "rom-bot@rom-rb.org"
|
24
|
+
git config --local user.name "rom-bot"
|
25
|
+
git add -A
|
26
|
+
git commit -m "[devtools] config sync" || echo "nothing changed"
|
27
|
+
- name: Push changes
|
28
|
+
uses: ad-m/github-push-action@master
|
29
|
+
with:
|
30
|
+
github_token: ${{ secrets.GH_PAT }}
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## v2.3.1 2022-12-07
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
* Add support for namespaced auto loading paths
|
6
|
+
* Fix jruby to version 9.3.*
|
7
|
+
|
8
|
+
[Compare v2.3.0...v2.3.1](https://github.com/rom-rb/rom-rails/compare/v2.3.0...v2.3.1)
|
9
|
+
|
10
|
+
## v2.3.0 2021-03-20
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
* Updated dependencies to allow Rails 6.1 (alex-lairan)
|
15
|
+
|
1
16
|
## v2.2.0 2019-09-12
|
2
17
|
|
3
18
|
### Changed
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
RAILS_VERSION = ENV.fetch("RAILS_VERSION", '6.
|
5
|
+
RAILS_VERSION = ENV.fetch("RAILS_VERSION", '6.1.1').freeze
|
6
6
|
|
7
7
|
%w(railties actionview actionpack activerecord).each do |name|
|
8
8
|
gem name, "~> #{RAILS_VERSION}"
|
@@ -11,13 +11,22 @@ end
|
|
11
11
|
gem 'byebug', platforms: :mri
|
12
12
|
gem 'sqlite3', platforms: [:mri, :rbx]
|
13
13
|
|
14
|
-
gem 'rom', git: 'https://github.com/rom-rb/rom', branch: 'master' do
|
15
|
-
gem 'rom-core'
|
16
|
-
gem 'rom-mapper'
|
17
|
-
gem 'rom-repository', group: :tools
|
18
|
-
end
|
19
14
|
|
20
|
-
|
15
|
+
|
16
|
+
if ENV["USE_ROM_MASTER"].eql?("true")
|
17
|
+
gem 'rom', git: 'https://github.com/rom-rb/rom', branch: 'master' do
|
18
|
+
gem 'rom-core'
|
19
|
+
gem 'rom-mapper'
|
20
|
+
gem 'rom-repository', group: :tools
|
21
|
+
end
|
22
|
+
|
23
|
+
gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
|
24
|
+
else
|
25
|
+
gem "rom"
|
26
|
+
gem "rom-sql"
|
27
|
+
|
28
|
+
gem "sequel", "5.31.0"
|
29
|
+
end
|
21
30
|
|
22
31
|
platforms :jruby do
|
23
32
|
gem 'jdbc-sqlite3'
|
@@ -26,7 +35,7 @@ end
|
|
26
35
|
group :test do
|
27
36
|
gem 'capybara'
|
28
37
|
gem 'codeclimate-test-reporter', require: nil
|
29
|
-
gem 'database_cleaner'
|
38
|
+
gem 'database_cleaner', "~> 1.8.1"
|
30
39
|
gem 'generator_spec'
|
31
40
|
gem 'rack-test'
|
32
41
|
gem 'rspec-rails', '~> 3.1'
|
data/README.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
[gem]: https://rubygems.org/gems/rom-rails
|
2
|
-
[
|
2
|
+
[actions]: https://github.com/rom-rb/rom-rails/actions
|
3
3
|
[codeclimate]: https://codeclimate.com/github/rom-rb/rom-rails
|
4
|
+
[codeacy]: https://www.codacy.com/gh/rom-rb/rom-rails
|
4
5
|
[coveralls]: https://coveralls.io/r/rom-rb/rom-rails
|
5
6
|
[inchpages]: http://inch-ci.org/github/rom-rb/rom-rails
|
6
7
|
|
7
|
-
# rom-rails
|
8
|
+
# rom-rails [![Join the chat at https://rom-rb.zulipchat.com](https://img.shields.io/badge/rom--rb-join%20chat-942283.svg)][chat]
|
8
9
|
|
9
10
|
[![Gem Version](https://badge.fury.io/rb/rom-rails.svg)][gem]
|
10
|
-
[![
|
11
|
+
[![CI Status](https://github.com/rom-rb/rom-rails/workflows/ci/badge.svg)][actions]
|
11
12
|
[![Code Climate](https://codeclimate.com/github/rom-rb/rom-rails/badges/gpa.svg)][codeclimate]
|
13
|
+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/81d5362ea6314dd09432fb238d79f481)][codeacy]
|
12
14
|
[![Test Coverage](https://codeclimate.com/github/rom-rb/rom-rails/badges/coverage.svg)][codeclimate]
|
13
15
|
[![Inline docs](http://inch-ci.org/github/rom-rb/rom-rails.svg?branch=master)][inchpages]
|
14
16
|
|
@@ -16,9 +18,9 @@ Rails integration for [Ruby Object Mapper](https://github.com/rom-rb/rom) which
|
|
16
18
|
ships with:
|
17
19
|
|
18
20
|
* Relation generators
|
21
|
+
* Repository generators
|
19
22
|
* Mapper generators
|
20
23
|
* Command generators
|
21
|
-
* Repository generators
|
22
24
|
|
23
25
|
## Tests
|
24
26
|
|
@@ -32,13 +34,14 @@ To run tests:
|
|
32
34
|
You can read more about ROM and Rails on the official website:
|
33
35
|
|
34
36
|
* [Introduction to ROM](http://rom-rb.org/learn/)
|
35
|
-
* [Rails setup](http://rom-rb.org/learn/
|
37
|
+
* [Rails setup](http://rom-rb.org/learn/rails/)
|
36
38
|
|
37
39
|
|
38
40
|
## Community
|
39
41
|
|
40
|
-
* [
|
41
|
-
* [Discussion Forum](https://
|
42
|
+
* [Offical ROM blog](https://rom-rb.org/blog)
|
43
|
+
* [Discussion Forum](https://discourse.rom-rb.org)
|
44
|
+
* [Chat](https://rom-rb.zulipchat.com)
|
42
45
|
|
43
46
|
## License
|
44
47
|
|
data/db
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
spec/dummy/db
|
@@ -0,0 +1,165 @@
|
|
1
|
+
---
|
2
|
+
position: 3
|
3
|
+
chapter: Rails
|
4
|
+
title: Setup
|
5
|
+
---
|
6
|
+
|
7
|
+
Rails integration is provided by [rom-rails](https://github.com/rom-rb/rom-rails) project. Simply add it to your Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'rom-rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Configuring Railtie
|
14
|
+
|
15
|
+
Create a rom initializer:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
# config/initializers/rom.rb
|
19
|
+
ROM::Rails::Railtie.configure do |config|
|
20
|
+
config.gateways[:default] = [:sql, ENV.fetch('DATABASE_URL')]
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
You can provide additional adapter-specific options, for example you can enable specific sql plugins for postgres:
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
# config/initializers/rom.rb
|
28
|
+
ROM::Rails::Railtie.configure do |config|
|
29
|
+
config.gateways[:default] = [:sql,
|
30
|
+
ENV.fetch('DATABASE_URL'), extensions: [:pg_hstore]
|
31
|
+
]
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
You can also provide a list of relations that should not be inferred from your schema automatically:
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
# config/initializers/rom.rb
|
39
|
+
ROM::Rails::Railtie.configure do |config|
|
40
|
+
config.gateways[:default] = [:sql,
|
41
|
+
ENV.fetch('DATABASE_URL'), not_inferrable_relations: [:schema_migrations]
|
42
|
+
]
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Migration Tasks
|
47
|
+
|
48
|
+
The railtie provides rake tasks for managing your database schema. You need to enable them in your `Rakefile`:
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
require 'rom/sql/rake_task'
|
52
|
+
```
|
53
|
+
|
54
|
+
After that, you have access to following tasks:
|
55
|
+
|
56
|
+
* `rake db:create_migration[migration_name]` - creates a new migration file
|
57
|
+
* `rake db:migrate` - runs pending migrations
|
58
|
+
* `rake db:clean` - cleans the database
|
59
|
+
* `rake db:reset` - drops tables and re-runs migrations
|
60
|
+
|
61
|
+
## Accessing Container
|
62
|
+
|
63
|
+
In Rails environment ROM container is accessible via `ROM.env`:
|
64
|
+
|
65
|
+
``` ruby
|
66
|
+
ROM.env # returns the container
|
67
|
+
```
|
68
|
+
|
69
|
+
In your controllers you can access ROM container by `rom` variable:
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
class UsersController < ApplicationController
|
73
|
+
def show
|
74
|
+
@user = rom.relation(:users).by_id(params[:id]).one
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
^WARNING
|
80
|
+
Accessing the global container directly is considered as a bad practice. The recommended way is to use a DI mechanism to inject specific ROM components as dependencies into your objects.
|
81
|
+
|
82
|
+
For example you can use [dry-container](https://github.com/dryrb/dry-container) and [dry-auto_inject](https://github.com/dryrb/dry-auto_inject) to define your own application container and specify dependencies there to have them automatically injected.
|
83
|
+
|
84
|
+
See [rom-rails-skeleton](https://github.com/solnic/rom-rails-skeleton) for an example of such setup.
|
85
|
+
^
|
86
|
+
|
87
|
+
## Defining Relations
|
88
|
+
|
89
|
+
Relation class definitions are automatically loaded from `app/relations`. The following code defines a `users` relation for the `:sql` adapter:
|
90
|
+
|
91
|
+
``` ruby
|
92
|
+
class Users < ROM::Relation[:sql]
|
93
|
+
# some methods
|
94
|
+
end
|
95
|
+
|
96
|
+
# access registered relation via container
|
97
|
+
ROM.env.relations[:users]
|
98
|
+
```
|
99
|
+
|
100
|
+
## Defining Commands
|
101
|
+
|
102
|
+
Command class definitions are automatically loaded from `app/commands`. The following code defines a command which inserts data into `users` relation:
|
103
|
+
|
104
|
+
``` ruby
|
105
|
+
# app/commands/create_user.rb
|
106
|
+
class CreateUser < ROM::Commands::Create[:sql]
|
107
|
+
relation :users
|
108
|
+
register_as :create
|
109
|
+
result :one
|
110
|
+
end
|
111
|
+
|
112
|
+
# access registered relation via container
|
113
|
+
ROM.env.commands[:users][:create]
|
114
|
+
```
|
115
|
+
|
116
|
+
## Defining Custom Mappers
|
117
|
+
|
118
|
+
If you want to use custom mappers you can place them under `app/mappers`:
|
119
|
+
|
120
|
+
``` ruby
|
121
|
+
# app/mappers/user_mapper.rb
|
122
|
+
class UserMapper < ROM::Mapper
|
123
|
+
relation :users
|
124
|
+
|
125
|
+
# some mapping logic
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
129
|
+
## Running alongside ActiveRecord
|
130
|
+
|
131
|
+
There might be some cases where you will want to run ROM alongside ActiveRecord. Since ROM is designed to work independently, you will need to take few additional steps. ROM creates its own connections and Rails above version 5 won't allow you to drop the database since there are active connections on it.
|
132
|
+
|
133
|
+
``` ruby
|
134
|
+
# lib/tasks/db.rake
|
135
|
+
task :remove_rom_connection => [:environment] do
|
136
|
+
ROM.env && ROM.env.disconnect
|
137
|
+
end
|
138
|
+
|
139
|
+
Rake::Task["db:drop"].clear_prerequisites()
|
140
|
+
Rake::Task["db:drop"].enhance [:remove_rom_connection, :load_config, :check_protected_environments]
|
141
|
+
|
142
|
+
Rake::Task["db:reset"].clear_prerequisites()
|
143
|
+
Rake::Task["db:reset"].enhance [:remove_rom_connection, "db:drop", "db:setup"]
|
144
|
+
```
|
145
|
+
|
146
|
+
Since migrations (and other) tasks require environment, ROM will be loaded and will throw an exception, because relations will try to load tables before migrations have actually run. We know this is an ugly solution, but we are working hard to solve this case. This monkey patch will give you reasonable information to act upon if the necessity arises.
|
147
|
+
|
148
|
+
``` ruby
|
149
|
+
# config/initializers/rom_monkey.rb
|
150
|
+
module ROM
|
151
|
+
module Rails
|
152
|
+
class Railtie < ::Rails::Railtie
|
153
|
+
alias_method :create_container!, :create_container
|
154
|
+
def create_container
|
155
|
+
begin
|
156
|
+
create_container!
|
157
|
+
rescue => e
|
158
|
+
puts "Container failed to initialize because of #{e.inspect}"
|
159
|
+
puts "This message comes from the monkey patch in #{__FILE__}, if you are using rake, then this is fine"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
```
|
data/lib/rom/rails/railtie.rb
CHANGED
@@ -30,7 +30,7 @@ module ROM
|
|
30
30
|
initializer 'rom.adjust_eager_load_paths' do |app|
|
31
31
|
paths =
|
32
32
|
auto_registration_paths.inject([]) do |result, root_path|
|
33
|
-
result.concat(COMPONENT_DIRS.map { |dir| ::Rails.root.join(root_path, dir).to_s })
|
33
|
+
result.concat(COMPONENT_DIRS.map { |dir| ::Rails.root.join(root_path.is_a?(Hash) ? root_path[:path] : root_path, dir).to_s })
|
34
34
|
end
|
35
35
|
|
36
36
|
app.config.eager_load_paths -= paths
|
@@ -40,9 +40,18 @@ module ROM
|
|
40
40
|
load "rom/rails/tasks/db.rake" unless active_record?
|
41
41
|
end
|
42
42
|
|
43
|
+
# Load ROM-related application code on startup
|
44
|
+
config.after_initialize do
|
45
|
+
if !::Rails.application.config.rom.reload_on_each_request
|
46
|
+
ROM.env = Railtie.create_container
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
43
50
|
# Reload ROM-related application code on each request.
|
44
|
-
config.to_prepare do |
|
45
|
-
|
51
|
+
config.to_prepare do |prepare_conf|
|
52
|
+
if ::Rails.application.config.rom.reload_on_each_request
|
53
|
+
ROM.env = Railtie.create_container
|
54
|
+
end
|
46
55
|
end
|
47
56
|
|
48
57
|
console do |_app|
|
@@ -78,7 +87,11 @@ module ROM
|
|
78
87
|
configuration = create_configuration
|
79
88
|
|
80
89
|
auto_registration_paths.each do |root_path|
|
81
|
-
|
90
|
+
if root_path.is_a? Hash
|
91
|
+
configuration.auto_registration(::Rails.root.join(root_path[:path]), namespace: root_path[:namespace])
|
92
|
+
else
|
93
|
+
configuration.auto_registration(::Rails.root.join(root_path), namespace: false)
|
94
|
+
end
|
82
95
|
end
|
83
96
|
|
84
97
|
ROM.container(configuration)
|
data/lib/rom/rails/version.rb
CHANGED
data/log
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
spec/dummy/log
|
data/rom-rails.gemspec
CHANGED
@@ -16,11 +16,17 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
+
spec.metadata = {
|
20
|
+
"bug_tracker_uri" => "https://github.com/rom-rb/rom-rails/issues",
|
21
|
+
"changelog_uri" => "https://github.com/rom-rb/rom-rails/blob/master/CHANGELOG.md",
|
22
|
+
"source_code_uri" => "https://github.com/rom-rb/rom-rails",
|
23
|
+
}
|
24
|
+
|
19
25
|
spec.add_runtime_dependency 'addressable', '~> 2.3'
|
20
|
-
spec.add_runtime_dependency 'dry-core', '~> 0.
|
26
|
+
spec.add_runtime_dependency 'dry-core', '~> 0.4'
|
21
27
|
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
22
|
-
spec.add_runtime_dependency 'railties', '>= 3.0', '< 6.
|
23
|
-
spec.add_runtime_dependency 'rom', '~> 5.
|
28
|
+
spec.add_runtime_dependency 'railties', '>= 3.0', '< 6.2'
|
29
|
+
spec.add_runtime_dependency 'rom', '~> 5.2'
|
24
30
|
|
25
31
|
spec.add_development_dependency "bundler"
|
26
32
|
spec.add_development_dependency "rake"
|
@@ -4,4 +4,5 @@ ROM::Rails::Railtie.configure do |config|
|
|
4
4
|
config.gateways[:sql] = [:sql, "#{scheme}://#{Rails.root}/db/#{Rails.env}.sqlite3"]
|
5
5
|
config.gateways[:default] = [:test_adapter, foo: :bar]
|
6
6
|
config.auto_registration_paths += [Rails.root.join('lib', 'additional_app', 'persistence')]
|
7
|
+
config.auto_registration_paths += [{path: Rails.root.join('lib', 'namespaced_app', 'persistence'), namespace: 'NamespacedApp::Persistence'}]
|
7
8
|
end
|
@@ -7,7 +7,12 @@ RSpec.describe 'ROM initializer' do
|
|
7
7
|
expect(rom.relations.dummy).to eql(relation)
|
8
8
|
end
|
9
9
|
|
10
|
-
it 'loads commands from
|
10
|
+
it 'loads commands from additional auto_registration_paths' do
|
11
11
|
expect(rom.commands.tasks.create_additional).to be_a(CreateAdditionalTask)
|
12
12
|
end
|
13
|
+
|
14
|
+
it 'allows namespace configuration on autoload paths' do
|
15
|
+
puts rom.commands.tasks.elements
|
16
|
+
expect(rom.commands.tasks.namespaced_additional).to be_a(NamespacedApp::Persistence::Commands::CreateAdditionalTask)
|
17
|
+
end
|
13
18
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Flipse
|
8
8
|
- Piotr Solnica
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0.
|
34
|
+
version: '0.4'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0.
|
41
|
+
version: '0.4'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: dry-equalizer
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,7 +62,7 @@ dependencies:
|
|
62
62
|
version: '3.0'
|
63
63
|
- - "<"
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: '6.
|
65
|
+
version: '6.2'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,21 +72,21 @@ dependencies:
|
|
72
72
|
version: '3.0'
|
73
73
|
- - "<"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '6.
|
75
|
+
version: '6.2'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: rom
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '5.
|
82
|
+
version: '5.2'
|
83
83
|
type: :runtime
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '5.
|
89
|
+
version: '5.2'
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
91
|
name: bundler
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,7 +143,7 @@ dependencies:
|
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0.50'
|
146
|
-
description:
|
146
|
+
description:
|
147
147
|
email:
|
148
148
|
- cflipse@gmail.com
|
149
149
|
- piotr.solnica@gmail.com
|
@@ -151,17 +151,24 @@ executables: []
|
|
151
151
|
extensions: []
|
152
152
|
extra_rdoc_files: []
|
153
153
|
files:
|
154
|
+
- ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
|
155
|
+
- ".github/ISSUE_TEMPLATE/---bug-report.md"
|
156
|
+
- ".github/ISSUE_TEMPLATE/---feature-request.md"
|
157
|
+
- ".github/workflows/ci.yml"
|
158
|
+
- ".github/workflows/docsite.yml"
|
159
|
+
- ".github/workflows/sync_configs.yml"
|
154
160
|
- ".gitignore"
|
155
161
|
- ".rspec"
|
156
162
|
- ".rubocop.yml"
|
157
|
-
- ".travis.yml"
|
158
163
|
- CHANGELOG.md
|
164
|
+
- CODE_OF_CONDUCT.md
|
159
165
|
- CONTRIBUTING.md
|
160
166
|
- Gemfile
|
161
167
|
- LICENSE
|
162
168
|
- README.md
|
163
169
|
- Rakefile
|
164
170
|
- db
|
171
|
+
- docsite/source/index.html.md
|
165
172
|
- lib/generators/rom.rb
|
166
173
|
- lib/generators/rom/commands/templates/create.rb.erb
|
167
174
|
- lib/generators/rom/commands/templates/delete.rb.erb
|
@@ -237,6 +244,7 @@ files:
|
|
237
244
|
- spec/dummy/db/migrate/20150403194906_create_tags.rb
|
238
245
|
- spec/dummy/lib/additional_app/persistence/commands/create_additional_task.rb
|
239
246
|
- spec/dummy/lib/assets/.keep
|
247
|
+
- spec/dummy/lib/namespaced_app/persistence/commands/create_additional_task.rb
|
240
248
|
- spec/dummy/lib/rom/test_adapter.rb
|
241
249
|
- spec/dummy/lib/tasks/.keep
|
242
250
|
- spec/dummy/log/.keep
|
@@ -264,8 +272,11 @@ files:
|
|
264
272
|
homepage: http://rom-rb.org
|
265
273
|
licenses:
|
266
274
|
- MIT
|
267
|
-
metadata:
|
268
|
-
|
275
|
+
metadata:
|
276
|
+
bug_tracker_uri: https://github.com/rom-rb/rom-rails/issues
|
277
|
+
changelog_uri: https://github.com/rom-rb/rom-rails/blob/master/CHANGELOG.md
|
278
|
+
source_code_uri: https://github.com/rom-rb/rom-rails
|
279
|
+
post_install_message:
|
269
280
|
rdoc_options: []
|
270
281
|
require_paths:
|
271
282
|
- lib
|
@@ -280,8 +291,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
291
|
- !ruby/object:Gem::Version
|
281
292
|
version: '0'
|
282
293
|
requirements: []
|
283
|
-
rubygems_version: 3.
|
284
|
-
signing_key:
|
294
|
+
rubygems_version: 3.2.32
|
295
|
+
signing_key:
|
285
296
|
specification_version: 4
|
286
297
|
summary: Integrate Ruby Object Mapper with Rails
|
287
298
|
test_files:
|
@@ -334,6 +345,7 @@ test_files:
|
|
334
345
|
- spec/dummy/db/migrate/20150403194906_create_tags.rb
|
335
346
|
- spec/dummy/lib/additional_app/persistence/commands/create_additional_task.rb
|
336
347
|
- spec/dummy/lib/assets/.keep
|
348
|
+
- spec/dummy/lib/namespaced_app/persistence/commands/create_additional_task.rb
|
337
349
|
- spec/dummy/lib/rom/test_adapter.rb
|
338
350
|
- spec/dummy/lib/tasks/.keep
|
339
351
|
- spec/dummy/log/.keep
|
data/.travis.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
cache: bundler
|
4
|
-
bundler_args: --without yard guard benchmarks
|
5
|
-
script: "RAILS_ENV=test bundle exec rake app:db:reset app:spec"
|
6
|
-
rvm:
|
7
|
-
- 2.4.6
|
8
|
-
- 2.5.5
|
9
|
-
- 2.6.3
|
10
|
-
- jruby-9.2.7.0
|
11
|
-
env:
|
12
|
-
- RAILS_VERSION=6.0
|
13
|
-
- RAILS_VERSION=5.2
|
14
|
-
- RAILS_VERSION=5.1
|
15
|
-
- RAILS_VERSION=5.0
|
16
|
-
- RAILS_VERSION=4.2
|
17
|
-
notifications:
|
18
|
-
webhooks:
|
19
|
-
urls:
|
20
|
-
- https://rom-rb.zulipchat.com/api/v1/external/travis?api_key=S1S2GRkXHlzlaCGyUwm7o4lg50IZrwCH&stream=notifications&topic=ci
|
21
|
-
on_success: change
|
22
|
-
on_failure: always
|
23
|
-
on_start: false
|
24
|
-
matrix:
|
25
|
-
exclude:
|
26
|
-
- rvm: 2.4.6
|
27
|
-
env: RAILS_VERSION=6.0
|