Class: Treaty::Attribute::HelperMapper
- Inherits:
-
Object
- Object
- Treaty::Attribute::HelperMapper
- Defined in:
- lib/treaty/attribute/helper_mapper.rb
Overview
Maps DSL helper symbols to their simple mode option equivalents.
## Purpose
Helpers provide the most concise syntax for common options. They are syntactic sugar that gets converted to simple mode options.
## Available Helpers
-
‘:required` → `required: true`
-
‘:optional` → `required: false`
## Usage Examples
Helper mode (most concise):
string :title, :required
string :bio, :optional
Equivalent to simple mode:
string :title, required: true
string :bio, required: false
## Processing Flow
-
Helper mode: ‘string :title, :required`
-
HelperMapper: ‘:required` → `required: true`
-
OptionNormalizer: ‘required: true` → `{ is: true, message: nil }`
-
Final: Advanced mode used internally
## Adding New Helpers
To add a new helper: “‘ruby HELPER_MAPPINGS = {
required: { required: true },
optional: { required: false },
my_helper: { my_option: :smth } # New helper example
}.freeze “‘
Constant Summary collapse
- HELPER_MAPPINGS =
{ required: { required: true }, optional: { required: false } }.freeze
Class Method Summary collapse
-
.helper?(symbol) ⇒ Boolean
Checks if a symbol is a registered helper.
-
.map(helpers) ⇒ Hash
Maps helper symbols to their simple mode equivalents.
Class Method Details
.helper?(symbol) ⇒ Boolean
Checks if a symbol is a registered helper
66 67 68 |
# File 'lib/treaty/attribute/helper_mapper.rb', line 66 def helper?(symbol) HELPER_MAPPINGS.key?(symbol) end |
.map(helpers) ⇒ Hash
Maps helper symbols to their simple mode equivalents
55 56 57 58 59 60 |
# File 'lib/treaty/attribute/helper_mapper.rb', line 55 def map(helpers) helpers.each_with_object({}) do |helper, result| mapping = HELPER_MAPPINGS.fetch(helper) result.merge!(mapping) if mapping.present? end end |