Module: Axn::Internal::FieldConfig
- Defined in:
- lib/axn/internal/field_config.rb
Overview
Pure utility functions for inspecting field configuration objects.
Class Method Summary collapse
-
.boolean?(config) ⇒ Boolean
Determines if a field is declared as boolean type.
-
.optional?(config) ⇒ Boolean
Determines if a field is optional based on its validations.
Class Method Details
.boolean?(config) ⇒ Boolean
Determines if a field is declared as boolean type.
28 29 30 |
# File 'lib/axn/internal/field_config.rb', line 28 def boolean?(config) Array(config.validations.dig(:type, :klass)) == [:boolean] end |
.optional?(config) ⇒ Boolean
Determines if a field is optional based on its validations. A field is optional if:
-
It doesn’t have presence: true validation
-
Any validator has allow_blank: true
16 17 18 19 20 21 22 |
# File 'lib/axn/internal/field_config.rb', line 16 def optional?(config) validations = config.validations return true unless validations.key?(:presence) && validations[:presence] == true # Check if any validator has allow_blank: true validations.values.any? { |v| v.is_a?(Hash) && v[:allow_blank] == true } end |