better_model 1.3.0 → 2.1.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 +4 -4
- data/README.md +304 -167
- data/lib/better_model/archivable.rb +2 -2
- data/lib/better_model/predicable.rb +43 -62
- data/lib/better_model/searchable.rb +28 -1
- data/lib/better_model/stateable/configurator.rb +46 -46
- data/lib/better_model/stateable/errors.rb +8 -5
- data/lib/better_model/stateable/guard.rb +17 -17
- data/lib/better_model/stateable/transition.rb +14 -14
- data/lib/better_model/stateable.rb +11 -11
- data/lib/better_model/validatable/configurator.rb +12 -12
- data/lib/better_model/version.rb +1 -1
- metadata +3 -3
|
@@ -10,18 +10,18 @@ module BetterModel
|
|
|
10
10
|
# Esempio:
|
|
11
11
|
# validatable do
|
|
12
12
|
# # Validazioni base
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# check :title, :content, presence: true
|
|
14
|
+
# check :email, format: { with: URI::MailTo::EMAIL_REGEXP }
|
|
15
15
|
#
|
|
16
16
|
# # Validazioni condizionali
|
|
17
17
|
# validate_if :is_published? do
|
|
18
|
-
#
|
|
19
|
-
#
|
|
18
|
+
# check :published_at, presence: true
|
|
19
|
+
# check :author_id, presence: true
|
|
20
20
|
# end
|
|
21
21
|
#
|
|
22
22
|
# # Validazioni condizionali negate
|
|
23
23
|
# validate_unless :is_draft? do
|
|
24
|
-
#
|
|
24
|
+
# check :reviewer_id, presence: true
|
|
25
25
|
# end
|
|
26
26
|
#
|
|
27
27
|
# # Cross-field validations
|
|
@@ -54,11 +54,11 @@ module BetterModel
|
|
|
54
54
|
# @param options [Hash] Opzioni di validazione (presence, format, etc.)
|
|
55
55
|
#
|
|
56
56
|
# @example
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
57
|
+
# check :title, :content, presence: true
|
|
58
|
+
# check :email, format: { with: URI::MailTo::EMAIL_REGEXP }
|
|
59
|
+
# check :age, numericality: { greater_than: 0 }
|
|
60
60
|
#
|
|
61
|
-
def
|
|
61
|
+
def check(*fields, **options)
|
|
62
62
|
# Se siamo dentro un blocco condizionale, aggiungi alla condizione corrente
|
|
63
63
|
if @current_conditional
|
|
64
64
|
@current_conditional[:validations] << {
|
|
@@ -79,12 +79,12 @@ module BetterModel
|
|
|
79
79
|
#
|
|
80
80
|
# @example Con simbolo (metodo)
|
|
81
81
|
# validate_if :is_published? do
|
|
82
|
-
#
|
|
82
|
+
# check :published_at, presence: true
|
|
83
83
|
# end
|
|
84
84
|
#
|
|
85
85
|
# @example Con lambda
|
|
86
86
|
# validate_if -> { status == "published" } do
|
|
87
|
-
#
|
|
87
|
+
# check :published_at, presence: true
|
|
88
88
|
# end
|
|
89
89
|
#
|
|
90
90
|
def validate_if(condition, &block)
|
|
@@ -111,7 +111,7 @@ module BetterModel
|
|
|
111
111
|
#
|
|
112
112
|
# @example
|
|
113
113
|
# validate_unless :is_draft? do
|
|
114
|
-
#
|
|
114
|
+
# check :reviewer_id, presence: true
|
|
115
115
|
# end
|
|
116
116
|
#
|
|
117
117
|
def validate_unless(condition, &block)
|
data/lib/better_model/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: better_model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- alessiobussolari
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
97
|
requirements: []
|
|
98
|
-
rubygems_version: 3.5.
|
|
98
|
+
rubygems_version: 3.5.22
|
|
99
99
|
signing_key:
|
|
100
100
|
specification_version: 4
|
|
101
101
|
summary: Rails engine gem that extends ActiveRecord model functionality
|