Class: Axn::Core::Contract::ShapeConfig

Inherits:
Data
  • Object
show all
Includes:
FieldOptionality
Defined in:
lib/axn/core/contract.rb

Overview

One member declared inside a structured field's block (field :name, ...). Nested members live in validations[:members], so the tree is uniform at every depth and walked by both ShapeValidator (runtime) and axn-mcp (schema). method_call: opts the member into the sharp path — reading it by INVOKING it as a method on the element being validated (a non-Data PORO reader or an Array method) rather than reading declared data (Hash keys, Struct/OpenStruct/Data members). It is threaded to the member's validation read as permit_method_call:, the shape-block analog of a subfield's method_call: (PRO-2907).

field is always a Symbol on a constructed ShapeConfig: field "bar" and field :bar are one member name, and the schema keys a member's property by field.to_sym, so storing the Symbol makes the stored value the one every consumer reads. It is what keeps the declaration guard (which canonicalizes the name's rendering) and the reflected schema in step by construction — parallel conversions of an unnormalized name are two questions that can disagree. Same rule as a top-level field, whose name expects/exposes symbolize before anything else looks at it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FieldOptionality

#optional?

Constructor Details

#initialize(field:, validations:, metadata: {}, method_call: false, sensitive: false, user_facing: false) ⇒ ShapeConfig

Returns a new instance of ShapeConfig.



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/axn/core/contract.rb', line 320

def initialize(field:, validations:, metadata: {}, method_call: false, sensitive: false, user_facing: false)
  # Validate at construction so a member's grammar holds however the ShapeConfig is built — the block
  # form (via `_build_shape_member`), a raw `shape:` kwarg supplying pre-built ShapeConfigs, and the
  # declaration walk's own snapshot of a member of any other class. The walk still reads and checks each
  # value itself, ahead of this: that keeps the error in ITS order (a member carrying both a bad
  # `sensitive:` and an untraversable nested shape is reported as the value defect), and the read it makes
  # is the one it stores. Here the check is the first thing the block form meets.
  Contract.validate_shape_member_name!(field)
  Contract.validate_user_facing!(user_facing)
  Contract.validate_sensitive!(sensitive)
  # `to_sym` is dispatched, so a String SUBCLASS could return something other than its own spelling —
  # but converting once is exactly what makes that harmless: every consumer then reads the one
  # stored Symbol, so a surprising conversion picks a different property name rather than splitting
  # the guard from the schema. That is why this must be the ONLY conversion of the name on every route
  # here: the declaration walk canonicalizes a duck-typed member's name itself, beside the duplicate
  # check that judges it, and hands the Symbol down — so this is a no-op for a member the walk built,
  # and the whole normalization for one built directly (the `field "bar"` block form, a pre-built
  # ShapeConfig in a raw `shape:`, a config assigned via `internal_field_configs=`), which is why it
  # stays.
  super(field: field.to_sym, validations:, metadata:, method_call:, sensitive:, user_facing:)
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



319
320
321
# File 'lib/axn/core/contract.rb', line 319

def field
  @field
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



319
320
321
# File 'lib/axn/core/contract.rb', line 319

def 
  @metadata
end

#method_callObject (readonly)

Returns the value of attribute method_call

Returns:

  • (Object)

    the current value of method_call



319
320
321
# File 'lib/axn/core/contract.rb', line 319

def method_call
  @method_call
end

#sensitiveObject (readonly)

Returns the value of attribute sensitive

Returns:

  • (Object)

    the current value of sensitive



319
320
321
# File 'lib/axn/core/contract.rb', line 319

def sensitive
  @sensitive
end

#user_facingObject (readonly)

Returns the value of attribute user_facing

Returns:

  • (Object)

    the current value of user_facing



319
320
321
# File 'lib/axn/core/contract.rb', line 319

def user_facing
  @user_facing
end

#validationsObject (readonly)

Returns the value of attribute validations

Returns:

  • (Object)

    the current value of validations



319
320
321
# File 'lib/axn/core/contract.rb', line 319

def validations
  @validations
end

Instance Method Details

#descriptionObject



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

def description = [:description]