Class: Axn::Core::Contract::FieldConfig

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

Methods included from FieldOptionality

#optional?

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

#defaultObject (readonly)

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def default
  @default
end

#fieldObject (readonly)

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def field
  @field
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def 
  @metadata
end

#method_callObject (readonly)

Returns the value of attribute method_call

Returns:

  • (Object)

    the current value of method_call



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def method_call
  @method_call
end

#onObject (readonly)

Returns the value of attribute on

Returns:

  • (Object)

    the current value of on



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def on
  @on
end

#preprocessObject (readonly)

Returns the value of attribute preprocess

Returns:

  • (Object)

    the current value of preprocess



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def preprocess
  @preprocess
end

#reader_asObject (readonly)

Returns the value of attribute reader_as

Returns:

  • (Object)

    the current value of reader_as



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def reader_as
  @reader_as
end

#sensitiveObject (readonly)

Returns the value of attribute sensitive

Returns:

  • (Object)

    the current value of sensitive



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def sensitive
  @sensitive
end

#user_facingObject (readonly)

Returns the value of attribute user_facing

Returns:

  • (Object)

    the current value of user_facing



270
271
272
# File 'lib/axn/core/contract.rb', line 270

def user_facing
  @user_facing
end

#validationsObject (readonly)

Returns the value of attribute validations

Returns:

  • (Object)

    the current value of 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.

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


291
292
293
# File 'lib/axn/core/contract.rb', line 291

def boolean?
  Array(validations.dig(:type, :klass)) == [:boolean]
end

#descriptionObject



284
# File 'lib/axn/core/contract.rb', line 284

def description = [:description]

#subfield?Boolean

Returns:

  • (Boolean)


286
# File 'lib/axn/core/contract.rb', line 286

def subfield? = !on.nil?