Module: ActiveRecordCompose::Validations

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Validations::Callbacks
Included in:
Model
Defined in:
lib/active_record_compose/validations.rb

Instance Method Summary collapse

Instance Method Details

#save(**options) ⇒ void



16
17
18
# File 'lib/active_record_compose/validations.rb', line 16

def save(**options)
  perform_validations(options) ? super : false
end

#save!(**options) ⇒ void



20
21
22
# File 'lib/active_record_compose/validations.rb', line 20

def save!(**options)
  perform_validations(options) ? super : raise_validation_error
end

#valid?(context = nil) ⇒ Boolean

Runs all the validations and returns the result as true or false.

Parameters:

  • context (defaults to: nil)

    Validation context.

Returns:

  • (Boolean)

    true on success, false on failure.



28
# File 'lib/active_record_compose/validations.rb', line 28

def valid?(context = nil) = context_for_override_validation.with_override(context) { super }

#validate(context = nil) ⇒ Boolean

Alias for #valid?

Parameters:

  • context (defaults to: nil)

Returns:

  • (Boolean)

    true on success, false on failure.

See Also:



# File 'lib/active_record_compose/validations.rb', line 30

#validate!(context = nil) ⇒ void

Runs all the validations within the specified context. no errors are found, raises ActiveRecord::RecordInvalid otherwise.

Parameters:

  • context (defaults to: nil)

    Validation context.

Raises:

  • ActiveRecord::RecordInvalid

See Also:



# File 'lib/active_record_compose/validations.rb', line 36