better_model 2.0.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 +179 -196
- data/lib/better_model/archivable.rb +0 -1
- data/lib/better_model/predicable.rb +39 -79
- data/lib/better_model/searchable.rb +31 -4
- 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
- data/lib/better_model.rb +0 -4
- metadata +3 -9
- data/lib/better_model/schedulable/occurrence_calculator.rb +0 -1034
- data/lib/better_model/schedulable/schedule_builder.rb +0 -269
- data/lib/better_model/schedulable.rb +0 -356
- data/lib/generators/better_model/taggable/taggable_generator.rb +0 -129
- data/lib/generators/better_model/taggable/templates/README.tt +0 -62
- data/lib/generators/better_model/taggable/templates/migration.rb.tt +0 -21
|
@@ -32,18 +32,18 @@
|
|
|
32
32
|
#
|
|
33
33
|
# # Transizioni
|
|
34
34
|
# transition :confirm, from: :pending, to: :confirmed do
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
35
|
+
# check { items.any? }
|
|
36
|
+
# check :customer_valid?
|
|
37
|
+
# check if: :is_payable? # Statusable integration
|
|
38
38
|
#
|
|
39
39
|
# validate { errors.add(:base, "Stock unavailable") unless stock_available? }
|
|
40
40
|
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
41
|
+
# before_transition { calculate_total }
|
|
42
|
+
# after_transition { send_confirmation_email }
|
|
43
43
|
# end
|
|
44
44
|
#
|
|
45
45
|
# transition :pay, from: :confirmed, to: :paid do
|
|
46
|
-
#
|
|
46
|
+
# before_transition { charge_payment }
|
|
47
47
|
# end
|
|
48
48
|
#
|
|
49
49
|
# transition :cancel, from: [:pending, :confirmed], to: :cancelled
|
|
@@ -119,15 +119,15 @@ module BetterModel
|
|
|
119
119
|
# transition :publish, from: :draft, to: :published
|
|
120
120
|
# end
|
|
121
121
|
#
|
|
122
|
-
# @example Con
|
|
122
|
+
# @example Con checks e callbacks
|
|
123
123
|
# stateable do
|
|
124
124
|
# state :pending, initial: true
|
|
125
125
|
# state :confirmed
|
|
126
126
|
#
|
|
127
127
|
# transition :confirm, from: :pending, to: :confirmed do
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
#
|
|
128
|
+
# check { valid? }
|
|
129
|
+
# before_transition { prepare_confirmation }
|
|
130
|
+
# after_transition { send_notification }
|
|
131
131
|
# end
|
|
132
132
|
# end
|
|
133
133
|
#
|
|
@@ -270,7 +270,7 @@ module BetterModel
|
|
|
270
270
|
# @param event [Symbol] Nome della transizione
|
|
271
271
|
# @param metadata [Hash] Metadata opzionale da salvare nella StateTransition
|
|
272
272
|
# @raise [InvalidTransitionError] Se la transizione non è valida
|
|
273
|
-
# @raise [
|
|
273
|
+
# @raise [CheckFailedError] Se un check fallisce
|
|
274
274
|
# @raise [ValidationFailedError] Se una validazione fallisce
|
|
275
275
|
# @return [Boolean] true se la transizione ha successo
|
|
276
276
|
#
|
|
@@ -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
data/lib/better_model.rb
CHANGED
|
@@ -19,9 +19,6 @@ require "better_model/stateable/errors"
|
|
|
19
19
|
require "better_model/stateable/guard"
|
|
20
20
|
require "better_model/stateable/transition"
|
|
21
21
|
require "better_model/taggable"
|
|
22
|
-
require "better_model/schedulable"
|
|
23
|
-
require "better_model/schedulable/schedule_builder"
|
|
24
|
-
require "better_model/schedulable/occurrence_calculator"
|
|
25
22
|
|
|
26
23
|
module BetterModel
|
|
27
24
|
extend ActiveSupport::Concern
|
|
@@ -38,6 +35,5 @@ module BetterModel
|
|
|
38
35
|
include BetterModel::Validatable
|
|
39
36
|
include BetterModel::Stateable
|
|
40
37
|
include BetterModel::Taggable
|
|
41
|
-
include BetterModel::Schedulable
|
|
42
38
|
end
|
|
43
39
|
end
|
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: 2.
|
|
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-
|
|
11
|
+
date: 2025-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -46,9 +46,6 @@ files:
|
|
|
46
46
|
- lib/better_model/permissible.rb
|
|
47
47
|
- lib/better_model/predicable.rb
|
|
48
48
|
- lib/better_model/railtie.rb
|
|
49
|
-
- lib/better_model/schedulable.rb
|
|
50
|
-
- lib/better_model/schedulable/occurrence_calculator.rb
|
|
51
|
-
- lib/better_model/schedulable/schedule_builder.rb
|
|
52
49
|
- lib/better_model/searchable.rb
|
|
53
50
|
- lib/better_model/sortable.rb
|
|
54
51
|
- lib/better_model/state_transition.rb
|
|
@@ -73,9 +70,6 @@ files:
|
|
|
73
70
|
- lib/generators/better_model/stateable/templates/README
|
|
74
71
|
- lib/generators/better_model/stateable/templates/install_migration.rb.tt
|
|
75
72
|
- lib/generators/better_model/stateable/templates/migration.rb.tt
|
|
76
|
-
- lib/generators/better_model/taggable/taggable_generator.rb
|
|
77
|
-
- lib/generators/better_model/taggable/templates/README.tt
|
|
78
|
-
- lib/generators/better_model/taggable/templates/migration.rb.tt
|
|
79
73
|
- lib/generators/better_model/traceable/templates/create_table_migration.rb.tt
|
|
80
74
|
- lib/generators/better_model/traceable/traceable_generator.rb
|
|
81
75
|
- lib/tasks/better_model_tasks.rake
|
|
@@ -101,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
101
95
|
- !ruby/object:Gem::Version
|
|
102
96
|
version: '0'
|
|
103
97
|
requirements: []
|
|
104
|
-
rubygems_version: 3.5.
|
|
98
|
+
rubygems_version: 3.5.22
|
|
105
99
|
signing_key:
|
|
106
100
|
specification_version: 4
|
|
107
101
|
summary: Rails engine gem that extends ActiveRecord model functionality
|