Class: Treaty::Entity::Attribute::HelperMapper
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::HelperMapper
- Defined in:
- lib/treaty/entity/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:
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
67 68 69 |
# File 'lib/treaty/entity/attribute/helper_mapper.rb', line 67 def helper?(symbol) HELPER_MAPPINGS.key?(symbol) end |
.map(helpers) ⇒ Hash
Maps helper symbols to their simple mode equivalents
56 57 58 59 60 61 |
# File 'lib/treaty/entity/attribute/helper_mapper.rb', line 56 def map(helpers) helpers.each_with_object({}) do |helper, result| mapping = HELPER_MAPPINGS.fetch(helper) result.merge!(mapping) if mapping.present? end end |