Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ Available callbacks are (listed in execution order):

```ruby
class RegistrationForm < YAAF::Form
attribute :email, :string
attribute :name, :string

normalizes :email, with: ->(email) { email.strip.downcase }
normalizes :name, with: ->(name) { name.strip.titleize }

Expand Down
2 changes: 1 addition & 1 deletion lib/yaaf/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class Form
include ::ActiveModel::Model
include ::ActiveModel::Validations::Callbacks
include ::ActiveRecord::Transactions
include ::ActiveModel::Attributes

if defined?(::ActiveModel::Attributes::Normalization)
include ::ActiveModel::Attributes
include ::ActiveModel::Attributes::Normalization
end

Expand Down
3 changes: 2 additions & 1 deletion spec/support/forms/multiple_errors_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class MultipleErrorsForm < YAAF::Form
attr_accessor :email, :name
attribute :email, :string
attribute :name, :string

validates :name, format: { with: /[a-zA-Z]+/ }
validates :email, format: { with: /\S+@\S+\.\S+/ }
Expand Down
3 changes: 2 additions & 1 deletion spec/support/forms/registration_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class RegistrationForm < YAAF::Form
attr_accessor :email, :name
attribute :email, :string
attribute :name, :string

validates :name, format: { with: /[a-zA-Z]+/ }, allow_blank: true

Expand Down
3 changes: 2 additions & 1 deletion spec/support/forms/user_destroy_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class UserDestroyForm < YAAF::Form
attr_accessor :email, :name
attribute :email, :string
attribute :name, :string

before_save :mark_user_for_destruction

Expand Down
5 changes: 4 additions & 1 deletion spec/support/forms/with_commit_callbacks_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class WithCommitCallbacksForm < YAAF::Form
attr_accessor :email, :name, :after_counter
attribute :email, :string
attribute :name, :string

attr_accessor :after_counter

validates :name, format: { with: /[a-zA-Z]+/ }, allow_blank: true
after_commit { @after_counter += 1 }
Expand Down
5 changes: 4 additions & 1 deletion spec/support/forms/with_multiple_callbacks_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class WithMultipleCallbacksForm < YAAF::Form
attr_accessor :email, :name, :result
attribute :email, :string
attribute :name, :string

attr_accessor :result

validates :name, format: { with: /[a-zA-Z]+/ }, allow_blank: true
after_validation :add_to_after_validation_counter, :add_again_to_after_validation_counter
Expand Down
5 changes: 4 additions & 1 deletion spec/support/forms/with_rollback_callbacks_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class WithRollbackCallbacksForm < YAAF::Form
attr_accessor :email, :name, :after_counter
attribute :email, :string
attribute :name, :string

attr_accessor :after_counter

validates :name, format: { with: /[a-zA-Z]+/ }, allow_blank: true
after_rollback { @after_counter += 1 }
Expand Down
5 changes: 4 additions & 1 deletion spec/support/forms/with_save_callbacks_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class WithSaveCallbacksForm < YAAF::Form
attr_accessor :email, :name, :before_counter, :after_counter
attribute :email, :string
attribute :name, :string

attr_accessor :before_counter, :after_counter

validates :name, format: { with: /[a-zA-Z]+/ }, allow_blank: true
before_save :add_to_before_counter
Expand Down
5 changes: 4 additions & 1 deletion spec/support/forms/with_validation_callbacks_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class WithValidationCallbacksForm < YAAF::Form
attr_accessor :email, :name, :before_counter, :after_counter
attribute :email, :string
attribute :name, :string

attr_accessor :before_counter, :after_counter

validates :name, format: { with: /[a-zA-Z]+/ }, allow_blank: true
before_validation :add_to_before_counter
Expand Down