Class: Treaty::Attribute::Option::Modifiers::AsModifier
- Defined in:
- lib/treaty/attribute/option/modifiers/as_modifier.rb
Overview
Transforms attribute names during data processing.
## Usage Examples
Simple mode:
# Request: expects "handle", outputs as "value"
string :handle, as: :value
Advanced mode:
string :handle, as: { is: :value, message: nil }
## Use Cases
-
**Request to Service mapping**: “‘ruby request do
string :user_id, as: :idend # Input: { user_id: “123” } # Service receives: { id: “123” } “‘
-
**Service to Response mapping**: “‘ruby response 200 do
string :id, as: :user_idend # Service returns: { id: “123” } # Output: { user_id: “123” } “‘
## How It Works
AsModifier doesn’t transform values - it transforms attribute names. The orchestrator uses ‘target_name` to map source name to target name.
## Advanced Mode
Schema format: ‘{ is: :symbol, message: nil }`
Instance Method Summary collapse
-
#target_name ⇒ Symbol
Returns the target name for the attribute.
-
#transform_value(value) ⇒ Object
AsModifier doesn’t modify the value itself, only the name The renaming is handled by the orchestrator using target_name.
-
#transforms_name? ⇒ Boolean
Indicates that AsModifier transforms attribute names.
-
#validate_schema! ⇒ void
Validates that target name is a Symbol.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Treaty::Attribute::Option::Base
Instance Method Details
#target_name ⇒ Symbol
Returns the target name for the attribute
74 75 76 |
# File 'lib/treaty/attribute/option/modifiers/as_modifier.rb', line 74 def target_name option_value end |
#transform_value(value) ⇒ Object
AsModifier doesn’t modify the value itself, only the name The renaming is handled by the orchestrator using target_name
83 84 85 |
# File 'lib/treaty/attribute/option/modifiers/as_modifier.rb', line 83 def transform_value(value) value end |
#transforms_name? ⇒ Boolean
Indicates that AsModifier transforms attribute names
67 68 69 |
# File 'lib/treaty/attribute/option/modifiers/as_modifier.rb', line 67 def transforms_name? true end |
#validate_schema! ⇒ void
This method returns an undefined value.
Validates that target name is a Symbol
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/treaty/attribute/option/modifiers/as_modifier.rb', line 51 def validate_schema! target = option_value return if target.is_a?(Symbol) raise Treaty::Exceptions::Validation, I18n.t( "treaty.attributes.modifiers.as.invalid_type", attribute: @attribute_name, type: target.class ) end |