serradura / u-case

Represent use cases in a simple and powerful way while writing modular, expressive and sequentially logical code.
https://rubygems.org/gems/u-case
MIT License
527 stars 33 forks source link

Add new Micro::Case::Config (enable_attributes_accept = true) #90

Open serradura opened 4 years ago

serradura commented 4 years ago

Configurations:

Micro::Case.config do |config|
  config.enable_attributes_accept = true

  config.enable_activemodel_validation = true
end

Attributes changes:

attribute :first_name, accept: String, 
                      default: -> value { value.try(:strip) },
                      validates: { length: { maximum: 30 } }

# ---

attribute :first_name, accept: String, 
                      default: Kind::Try(:strip), # Kind::Try will be available as soon as possible
                      validates: { length: { maximum: 30 } }

The execution order will be:

  1. u-attributes: Fetch the default value
  2. u-attributes: Validate using the accept/reject (options https://github.com/serradura/u-attributes/issues/8)
  3. u-case: Valide using ActiveModel::Validation if the u-attributes validation was ok.