Class: Fractor::ConfigSchema::SchemaEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/fractor/config_schema.rb

Overview

Schema entry definition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options) ⇒ SchemaEntry

Returns a new instance of SchemaEntry.



33
34
35
36
37
38
39
# File 'lib/fractor/config_schema.rb', line 33

def initialize(name, **options)
  @name = name
  @type = options[:type]
  @default = options[:default]
  @optional = options.fetch(:optional, true)
  @description = options[:description]
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



31
32
33
# File 'lib/fractor/config_schema.rb', line 31

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



31
32
33
# File 'lib/fractor/config_schema.rb', line 31

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/fractor/config_schema.rb', line 31

def name
  @name
end

#optionalObject (readonly)

Returns the value of attribute optional.



31
32
33
# File 'lib/fractor/config_schema.rb', line 31

def optional
  @optional
end

#typeObject (readonly)

Returns the value of attribute type.



31
32
33
# File 'lib/fractor/config_schema.rb', line 31

def type
  @type
end

Instance Method Details

#validate(value) ⇒ Array<String>

Validate a value against this schema entry

Returns:

  • (Array<String>)

    Array of error messages (empty if valid)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fractor/config_schema.rb', line 43

def validate(value)
  errors = []

  # Check nil for optional fields
  if value.nil?
    errors << "#{name} is required" unless @optional
    return errors
  end

  # Type validation
  if @type && !type_matches?(value)
    errors << "#{name} must be of type #{type_description}, got #{value.class}"
  end

  errors
end