Class: Servactory::ToolKit::DynamicOptions::Must::WorkOption
- Inherits:
-
Object
- Object
- Servactory::ToolKit::DynamicOptions::Must::WorkOption
- Defined in:
- lib/servactory/tool_kit/dynamic_options/must.rb
Overview
Value object representing a parsed validation option.
## Purpose
WorkOption normalizes the various ways an option can be specified (simple value, hash with ‘:is` key, hash with custom message) into a consistent interface for validators.
## Attributes
-
‘name` - The option name symbol (e.g., `:min`, `:max`)
-
‘value` - The actual validation value (e.g., `10` for `min: 10`)
-
‘message` - Custom error message (String or Proc), or nil
-
‘properties` - Additional hash properties passed with the option
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name, data, body_key:, body_fallback:) ⇒ WorkOption
constructor
Creates a new WorkOption by parsing option data.
Constructor Details
#initialize(name, data, body_key:, body_fallback:) ⇒ WorkOption
Creates a new WorkOption by parsing option data.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/servactory/tool_kit/dynamic_options/must.rb', line 125 def initialize(name, data, body_key:, body_fallback:) @name = name # Extract the primary value from data. @value = if data.is_a?(Hash) && data.key?(body_key) data.delete(body_key) else data.presence || body_fallback end # Extract custom message if provided. @message = (data.is_a?(Hash) && data.key?(:message) ? data.delete(:message) : nil) # Remaining hash properties become additional configuration. @properties = data.is_a?(Hash) ? data : {} end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
114 115 116 |
# File 'lib/servactory/tool_kit/dynamic_options/must.rb', line 114 def @message end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
114 115 116 |
# File 'lib/servactory/tool_kit/dynamic_options/must.rb', line 114 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
114 115 116 |
# File 'lib/servactory/tool_kit/dynamic_options/must.rb', line 114 def properties @properties end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
114 115 116 |
# File 'lib/servactory/tool_kit/dynamic_options/must.rb', line 114 def value @value end |