iry 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -3
- data/README.md +29 -5
- data/VERSION +1 -1
- data/db/schema.pgsql +1 -0
- data/lib/iry.rb +3 -1
- data/package-lock.json +1795 -0
- data/package.json +29 -0
- data/sorbet/tapioca/config.yml +8 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e650372034f89b6bd6d8187f83f7e54ec43a9fa9cf69f4c1ec07ee091b07063c
|
4
|
+
data.tar.gz: 0dad363e7219745a1f92a0af6fe2348a98029f3740cd6031d46535a39c742dd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 460f2ebab05bbe7271634f5a7d5cb0ae6644d5f53982e3bec6ac0f8c9f6745ca5c8e3aea3f931649112a2b1641d411c788f9fc3aba643ae03c9e4f50b85784b7
|
7
|
+
data.tar.gz: 17a3e4033f3a731e110706db24b6b71f95b3059b7b113299cf6c651001e7f309b2402b867b7a974f9532ba89a7f499cb7533a2eebc8217bb693513923e8713af
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
## [
|
1
|
+
## [0.1.1](https://github.com/Fire-Dragon-DoL/iry/compare/v0.1.0...v0.1.1) (2023-07-07)
|
2
2
|
|
3
|
-
## [0.1.0] - 2023-07-04
|
4
3
|
|
5
|
-
|
4
|
+
|
5
|
+
# [0.1.0](https://github.com/Fire-Dragon-DoL/iry/compare/8a133c2c19b99881619a9e1c7c11076030755f66...v0.1.0) (2023-07-07)
|
6
|
+
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* **constraints:** check constraint is present ([2723ad7](https://github.com/Fire-Dragon-DoL/iry/commit/2723ad70d7dbb4cea4b4c6e92ce59627fae64c27))
|
11
|
+
* **constraints:** exclusion constraint is present ([bdb904a](https://github.com/Fire-Dragon-DoL/iry/commit/bdb904a80dd1f6b1960f2b8378490cc192deb83e))
|
12
|
+
* **constraints:** foreign key constraint is present ([efed498](https://github.com/Fire-Dragon-DoL/iry/commit/efed4986a10b40c77dcd063d8801eb77d605d807))
|
13
|
+
* **deps:** dependency surface is reduced ([ff4af7e](https://github.com/Fire-Dragon-DoL/iry/commit/ff4af7e365537e30a0d95bfdee84e681f54c155a))
|
14
|
+
* **project:** setup ([8a133c2](https://github.com/Fire-Dragon-DoL/iry/commit/8a133c2c19b99881619a9e1c7c11076030755f66))
|
15
|
+
* **ruby:** version is forced to >= 2.7 ([f386ce6](https://github.com/Fire-Dragon-DoL/iry/commit/f386ce6db3aab7399b71a15bfed8228884a82f16))
|
16
|
+
* **unique-constraint:** test is implemented ([c4266b9](https://github.com/Fire-Dragon-DoL/iry/commit/c4266b910757b6adef18db41dfa5dfd9353c1037))
|
data/README.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
[![Iry](https://github.com/Fire-Dragon-DoL/iry/actions/workflows/main.yml/badge.svg)](https://github.com/Fire-Dragon-DoL/iry/actions/workflows/main.yml) [![Gem Version](https://badge.fury.io/rb/iry.svg)](https://badge.fury.io/rb/iry)
|
2
|
+
|
1
3
|
# Iry
|
2
4
|
|
3
5
|
Convert constraint errors into Rails model validation errors.
|
4
6
|
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
https://rubydoc.info/gems/iry/frames
|
10
|
+
|
5
11
|
## Usage
|
6
12
|
|
7
13
|
Given the following database schema:
|
@@ -44,6 +50,7 @@ fail_user.errors.details.fetch(:unique_text) #=> [{error: :taken}]
|
|
44
50
|
Multiple constraints of the same or different types can be present on the model, as long as the `:name` is different.
|
45
51
|
|
46
52
|
The following constraint types are available:
|
53
|
+
|
47
54
|
- [`check_constraint`](#check_constraint)
|
48
55
|
- [`exclusion_constraint`](#exclusion_constraint)
|
49
56
|
- [`foreign_key_constraint`](#foreign_key_constraint)
|
@@ -53,7 +60,11 @@ The class method `.constraints` is also available, that returns all the constrai
|
|
53
60
|
|
54
61
|
## Constraints
|
55
62
|
|
56
|
-
### `check_constraint`
|
63
|
+
### [`check_constraint`](https://rubydoc.info/gems/iry/Iry%2FMacros:check_constraint)
|
64
|
+
|
65
|
+
```rbs
|
66
|
+
check_constraint(key, name: nil, message: :invalid) ⇒ void
|
67
|
+
```
|
57
68
|
|
58
69
|
Catches a specific check constraint violation.
|
59
70
|
|
@@ -61,7 +72,11 @@ Catches a specific check constraint violation.
|
|
61
72
|
- **name** (optional `String`) constraint name in the database, to detect constraint errors. Infferred if omitted
|
62
73
|
- **message** (optional `String` or `Symbol`) error message, defaults to `:invalid`
|
63
74
|
|
64
|
-
### `exclusion_constraint`
|
75
|
+
### [`exclusion_constraint`](https://rubydoc.info/gems/iry/Iry%2FMacros:exclusion_constraint)
|
76
|
+
|
77
|
+
```rbs
|
78
|
+
exclusion_constraint(key, name: nil, message: :taken) ⇒ void
|
79
|
+
```
|
65
80
|
|
66
81
|
Catches a specific exclusion constraint violation.
|
67
82
|
|
@@ -69,7 +84,11 @@ Catches a specific exclusion constraint violation.
|
|
69
84
|
- **name** (optional `String`) constraint name in the database, to detect constraint errors. Infferred if omitted
|
70
85
|
- **message** (optional `String` or `Symbol`) error message, defaults to `:taken`
|
71
86
|
|
72
|
-
### `foreign_key_constraint`
|
87
|
+
### [`foreign_key_constraint`](https://rubydoc.info/gems/iry/Iry%2FMacros:foreign_key_constraint)
|
88
|
+
|
89
|
+
```rbs
|
90
|
+
foreign_key_constraint(key_or_keys, name: nil, message: :required, error_key: nil) ⇒ void
|
91
|
+
```
|
73
92
|
|
74
93
|
Catches a specific foreign key constraint violation.
|
75
94
|
|
@@ -78,7 +97,11 @@ Catches a specific foreign key constraint violation.
|
|
78
97
|
- **message** (optional `String` or `Symbol`) error message, defaults to `:required`
|
79
98
|
- **error_key** (optional `Symbol`) which key will have validation errors added to
|
80
99
|
|
81
|
-
### `unique_constraint`
|
100
|
+
### [`unique_constraint`](https://rubydoc.info/gems/iry/Iry%2FMacros:unique_constraint)
|
101
|
+
|
102
|
+
```rbs
|
103
|
+
unique_constraint(key_or_keys, name: nil, message: :taken, error_key: nil) ⇒ void
|
104
|
+
```
|
82
105
|
|
83
106
|
Catches a specific foreign key constraint violation.
|
84
107
|
|
@@ -93,7 +116,7 @@ Catches a specific foreign key constraint violation.
|
|
93
116
|
are cleared
|
94
117
|
- `create!` and `update!` will raise `ActiveRecord::RecordNotSaved` for constraints that are caught by `iry`, instead
|
95
118
|
of `ActiveModel::ValidationError`
|
96
|
-
- Currently only PostgreSQL is supported
|
119
|
+
- Currently only PostgreSQL is supported with the `pg` gem, but it should be simple to add support for other databases.
|
97
120
|
|
98
121
|
## Installation
|
99
122
|
|
@@ -109,6 +132,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
109
132
|
|
110
133
|
**Requirements:**
|
111
134
|
- PostgreSQL with `psql`, `createdb`, `dropdb`
|
135
|
+
- NodeJS 18 with `npm`
|
112
136
|
|
113
137
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
114
138
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/db/schema.pgsql
CHANGED
@@ -6,6 +6,7 @@ create table if not exists users (
|
|
6
6
|
unique_text text unique not null default gen_random_uuid()::text check (unique_text != 'invalid'),
|
7
7
|
exclude_text text not null default gen_random_uuid()::text,
|
8
8
|
user_id uuid references users (id),
|
9
|
+
untracked_text text unique not null default gen_random_uuid()::text,
|
9
10
|
friend_user_id uuid references users (id),
|
10
11
|
created_at timestamp(6) not null,
|
11
12
|
updated_at timestamp(6) not null,
|
data/lib/iry.rb
CHANGED
@@ -38,7 +38,9 @@ module Iry
|
|
38
38
|
def self.included(klass)
|
39
39
|
klass.class_eval do
|
40
40
|
extend(Iry::Macros)
|
41
|
-
around_save
|
41
|
+
# Prepend ensures around save happens before all around_save callbacks
|
42
|
+
# adding the errors as soon as possible
|
43
|
+
around_save(Iry::Callbacks, prepend: true)
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|