Class: Axn::Core::Contract::FieldConfig
- Inherits:
-
Data
- Object
- Data
- Axn::Core::Contract::FieldConfig
- Includes:
- FieldOptionality
- Defined in:
- lib/axn/core/contract.rb
Overview
The one config type for every declared inbound/outbound field, top-level or subfield — a
top-level field is just the depth-0 case (on: nil). reader_as is the name of the
generated accessor method; it defaults to field (the wire key), but expects ..., as:/
prefix: decouple them so the caller-facing contract stays field while the in-action
reader gets its own name. on: names the parent reader a subfield is extracted from;
user_facing: reclassifies a violation of the field into a user-facing failure.
method_call: opts a subfield into the sharp path — resolving a segment by INVOKING it as a
method (Array methods, PORO readers, Data behavioral methods) rather than reading declared
data; it is threaded to the resolver as permit_method_call: (PRO-2898).
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#method_call ⇒ Object
readonly
Returns the value of attribute method_call.
-
#on ⇒ Object
readonly
Returns the value of attribute on.
-
#preprocess ⇒ Object
readonly
Returns the value of attribute preprocess.
-
#reader_as ⇒ Object
readonly
Returns the value of attribute reader_as.
-
#sensitive ⇒ Object
readonly
Returns the value of attribute sensitive.
-
#user_facing ⇒ Object
readonly
Returns the value of attribute user_facing.
-
#validations ⇒ Object
readonly
Returns the value of attribute validations.
Instance Method Summary collapse
-
#applied_default? ⇒ Boolean
Whether the declared default is applied at runtime: any non-nil default counts (
default: falseon a boolean is meaningful), matching top-level defaults' key-absence semantics. -
#boolean? ⇒ Boolean
Whether the field is declared
type: :boolean(drives the generated?predicate reader). - #description ⇒ Object
-
#initialize(field:, validations:, reader_as:, default: nil, preprocess: nil, sensitive: false, metadata: {}, user_facing: false, on: nil, method_call: false) ⇒ FieldConfig
constructor
A new instance of FieldConfig.
- #subfield? ⇒ Boolean
Methods included from FieldOptionality
Constructor Details
#initialize(field:, validations:, reader_as:, default: nil, preprocess: nil, sensitive: false, metadata: {}, user_facing: false, on: nil, method_call: false) ⇒ FieldConfig
Returns a new instance of FieldConfig.
271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/axn/core/contract.rb', line 271 def initialize(field:, validations:, reader_as:, default: nil, preprocess: nil, sensitive: false, metadata: {}, user_facing: false, on: nil, method_call: false) # THE choke point for a declared field's `sensitive:` and `user_facing:`, whichever DSL built it # (`expects`, `exposes`, an `on:` subfield, an ambient subfield, `Axn::Factory`): every stored # FieldConfig is built here, from kwargs, and nothing hands axn one it made itself. That is what makes # it the right place for BOTH — a config ASSIGNED onto a class (`internal_field_configs=`) never passes # the DSL, so a check that only lives there leaves the value unheld while the executor still resolves # it. See Contract.validate_sensitive! / .validate_user_facing!. Contract.validate_sensitive!(sensitive) Contract.validate_user_facing!(user_facing) super end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def default @default end |
#field ⇒ Object (readonly)
Returns the value of attribute field
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def field @field end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def @metadata end |
#method_call ⇒ Object (readonly)
Returns the value of attribute method_call
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def method_call @method_call end |
#on ⇒ Object (readonly)
Returns the value of attribute on
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def on @on end |
#preprocess ⇒ Object (readonly)
Returns the value of attribute preprocess
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def preprocess @preprocess end |
#reader_as ⇒ Object (readonly)
Returns the value of attribute reader_as
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def reader_as @reader_as end |
#sensitive ⇒ Object (readonly)
Returns the value of attribute sensitive
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def sensitive @sensitive end |
#user_facing ⇒ Object (readonly)
Returns the value of attribute user_facing
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def user_facing @user_facing end |
#validations ⇒ Object (readonly)
Returns the value of attribute validations
270 271 272 |
# File 'lib/axn/core/contract.rb', line 270 def validations @validations end |
Instance Method Details
#applied_default? ⇒ Boolean
Whether the declared default is applied at runtime: any non-nil default counts (default: false on a boolean is meaningful), matching top-level defaults' key-absence semantics.
Schema reflection keys off the same rule, so a declared falsey default is emitted and
relaxes requiredness exactly when the runtime would apply it.
299 300 301 |
# File 'lib/axn/core/contract.rb', line 299 def applied_default? !default.nil? end |
#boolean? ⇒ Boolean
Whether the field is declared type: :boolean (drives the generated ? predicate reader).
291 292 293 |
# File 'lib/axn/core/contract.rb', line 291 def boolean? Array(validations.dig(:type, :klass)) == [:boolean] end |
#description ⇒ Object
284 |
# File 'lib/axn/core/contract.rb', line 284 def description = [:description] |
#subfield? ⇒ Boolean
286 |
# File 'lib/axn/core/contract.rb', line 286 def subfield? = !on.nil? |