Class: Fractor::ConfigSchema::SchemaEntry
- Inherits:
-
Object
- Object
- Fractor::ConfigSchema::SchemaEntry
- Defined in:
- lib/fractor/config_schema.rb
Overview
Schema entry definition
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, **options) ⇒ SchemaEntry
constructor
A new instance of SchemaEntry.
-
#validate(value) ⇒ Array<String>
Validate a value against this schema entry.
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, **) @name = name @type = [:type] @default = [:default] @optional = .fetch(:optional, true) @description = [:description] end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
31 32 33 |
# File 'lib/fractor/config_schema.rb', line 31 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
31 32 33 |
# File 'lib/fractor/config_schema.rb', line 31 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/fractor/config_schema.rb', line 31 def name @name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
31 32 33 |
# File 'lib/fractor/config_schema.rb', line 31 def optional @optional end |
#type ⇒ Object (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
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 |