Class: Prosereflect::Schema::Attribute
- Inherits:
-
Object
- Object
- Prosereflect::Schema::Attribute
- Defined in:
- lib/prosereflect/schema/attribute.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #has_default? ⇒ Boolean
-
#initialize(name:, default: nil, validate: nil) ⇒ Attribute
constructor
A new instance of Attribute.
- #required? ⇒ Boolean
- #validate_value(value) ⇒ Object
Constructor Details
#initialize(name:, default: nil, validate: nil) ⇒ Attribute
Returns a new instance of Attribute.
8 9 10 11 12 |
# File 'lib/prosereflect/schema/attribute.rb', line 8 def initialize(name:, default: nil, validate: nil) @name = name @default = default @validate = validate end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/prosereflect/schema/attribute.rb', line 6 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/prosereflect/schema/attribute.rb', line 6 def name @name end |
Instance Method Details
#has_default? ⇒ Boolean
14 15 16 |
# File 'lib/prosereflect/schema/attribute.rb', line 14 def has_default? !@default.nil? end |
#required? ⇒ Boolean
18 19 20 |
# File 'lib/prosereflect/schema/attribute.rb', line 18 def required? !has_default? end |
#validate_value(value) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/prosereflect/schema/attribute.rb', line 22 def validate_value(value) return true if @validate.nil? return @validate.call(value) if @validate.respond_to?(:call) # Handle string-based type validation like "string", "number", "string|null" validate_type(value, @validate.to_s) end |