iry 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21ffff3b3300f8b100bbe0af995b5d0736260f8c17ca93c9f6e66b44b9fd3088
4
- data.tar.gz: 5df2033893b5f5d8e8bdf7c97061f8bacc185620daa9a42b87167e945cf534ae
3
+ metadata.gz: e650372034f89b6bd6d8187f83f7e54ec43a9fa9cf69f4c1ec07ee091b07063c
4
+ data.tar.gz: 0dad363e7219745a1f92a0af6fe2348a98029f3740cd6031d46535a39c742dd2
5
5
  SHA512:
6
- metadata.gz: dbc9d0e8a465a34834007308bce3955ed5248c8a93699f81a346c6472cf153dc3df982217868a0392b510f32a0d3fc7ead3c6e9474bc55a508fd976a03e64be4
7
- data.tar.gz: 3810fa311f0c09b51dd681eeaa31d6e36eb6a9ee3c131042e43cc525a0231a8df8cbe6f4ae2a55588de95ca3c7e950bf4ef36bc56410214c9adc71f1ceea1ab7
6
+ metadata.gz: 460f2ebab05bbe7271634f5a7d5cb0ae6644d5f53982e3bec6ac0f8c9f6745ca5c8e3aea3f931649112a2b1641d411c788f9fc3aba643ae03c9e4f50b85784b7
7
+ data.tar.gz: 17a3e4033f3a731e110706db24b6b71f95b3059b7b113299cf6c651001e7f309b2402b867b7a974f9532ba89a7f499cb7533a2eebc8217bb693513923e8713af
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
- ## [Unreleased]
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
- - Initial release
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, with the `pg` gem, but it's easy to add support for other databases.
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
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(Iry::Callbacks)
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