Module: StructuredParams::AttributeMethods

Extended by:
ActiveSupport::Concern
Included in:
Params
Defined in:
lib/structured_params/attribute_methods.rb,
sig/structured_params/attribute_methods.rbs

Overview

Extends ActiveModel::Attributes to define attr_before_type_cast accessors for each attribute, mirroring ActiveRecord::AttributeMethods::BeforeTypeCast.

Example:

class UserParams < StructuredParams::Params
attribute :age, :integer
end

params = UserParams.new(age: "42abc")
params.age                    # => 42  (type-cast)
params.age_before_type_cast   # => "42abc"  (raw input)

Class Method Summary collapse

Class Method Details

.attributevoid

This method returns an undefined value.

Override attribute to also define attr_before_type_cast via ActiveModel::Attribute#value_before_type_cast : (Symbol name, *untyped) -> void

Parameters:

  • name (Symbol)
  • (Object)


21
# File 'sig/structured_params/attribute_methods.rbs', line 21

def self.attribute: (Symbol name, *untyped) -> void