Class: SpecForge::Normalizer::Structure

Inherits:
Hash
  • Object
show all
Defined in:
lib/spec_forge/normalizer/structure.rb

Overview

Represents a parsed structure definition for normalization

Structure definitions specify the expected shape of input data, including types, defaults, aliases, and nested structures. They are loaded from YAML files and normalized themselves.

Constant Summary collapse

STRUCTURE =

Meta-structure defining the format of structure definitions

Returns:

  • (Hash)
{
  type: {
    type: [String, Array, Class],
    default: nil, # Important to default this to nil so other logic can handle it
    required: true,
    validator: :present?
  },
  default: {
    type: [String, NilClass, Numeric, Array, Hash, TrueClass, FalseClass]
  },
  required: {
    type: [TrueClass, FalseClass]
  },
  aliases: {
    type: Array,
    structure: {type: String}
  },
  structure: {
    type: Hash
  },
  validator: {
    type: String
  },
  transformer: {
    type: String
  },
  description: {
    type: String
  },
  examples: {
    type: Array,
    structure: {
      type: [String, Integer, Float, Hash, Array, TrueClass, FalseClass]
    }
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, label: "") ⇒ Structure

Creates a new Structure from the given input definition

Parameters:

  • input (Hash)

    The raw structure definition from YAML

  • label (String) (defaults to: "")

    Human-readable label for error messages



64
65
66
67
68
69
70
71
72
# File 'lib/spec_forge/normalizer/structure.rb', line 64

def initialize(input, label: "")
  @label = label

  # Pull in the data
  deep_merge!(input)

  # And normalize
  normalize
end

Instance Attribute Details

#labelString (readonly)

Returns Human-readable label for this structure.

Returns:

  • (String)

    Human-readable label for this structure



54
55
56
# File 'lib/spec_forge/normalizer/structure.rb', line 54

def label
  @label
end