Module: Typelizer::DSL::ClassMethods
- Defined in:
- lib/typelizer/dsl.rb
Instance Attribute Summary collapse
-
#keyless_type ⇒ Object
Returns the value of attribute keyless_type.
Instance Method Summary collapse
-
#_own_typelizer_multi_attributes ⇒ Object
Returns own Set (initializing if needed) for writing.
-
#_typelizer_multi_attributes ⇒ Object
Returns union of own + ancestors’ multi attributes.
- #store_type(attribute_name, name, options) ⇒ Object
-
#typelize(type = nil, type_params = {}, **attributes) ⇒ Object
save association of serializer attributes to type can be invoked multiple times.
-
#typelize_from(model) ⇒ Object
save association of serializer to model.
- #typelize_meta(**attributes) ⇒ Object
- #typelizer_config(&block) ⇒ Object
Instance Attribute Details
#keyless_type ⇒ Object
Returns the value of attribute keyless_type.
53 54 55 |
# File 'lib/typelizer/dsl.rb', line 53 def keyless_type @keyless_type end |
Instance Method Details
#_own_typelizer_multi_attributes ⇒ Object
Returns own Set (initializing if needed) for writing
66 67 68 |
# File 'lib/typelizer/dsl.rb', line 66 def _own_typelizer_multi_attributes @_typelizer_multi_attributes ||= Set.new end |
#_typelizer_multi_attributes ⇒ Object
Returns union of own + ancestors’ multi attributes
56 57 58 59 60 61 62 63 |
# File 'lib/typelizer/dsl.rb', line 56 def _typelizer_multi_attributes result = @_typelizer_multi_attributes || Set.new if superclass.respond_to?(:_typelizer_multi_attributes) superclass._typelizer_multi_attributes | result else result end end |
#store_type(attribute_name, name, options) ⇒ Object
74 75 76 77 78 |
# File 'lib/typelizer/dsl.rb', line 74 def store_type(attribute_name, name, ) ensure_type_store(attribute_name) instance_variable_get("@#{attribute_name}")[name.to_sym] ||= {} instance_variable_get("@#{attribute_name}")[name.to_sym].merge!() end |
#typelize(type = nil, type_params = {}, **attributes) ⇒ Object
save association of serializer attributes to type can be invoked multiple times
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/typelizer/dsl.rb', line 41 def typelize(type = nil, type_params = {}, **attributes) if type # Parse type shortcuts like 'string?', 'string[]' parsed = TypeParser.parse(type) merged_params = parsed.merge(type_params).merge(attributes) actual_type = merged_params.delete(:type) @keyless_type = [actual_type, merged_params] else assign_type_information(:_typelizer_attributes, attributes) end end |
#typelize_from(model) ⇒ Object
save association of serializer to model
35 36 37 |
# File 'lib/typelizer/dsl.rb', line 35 def typelize_from(model) define_singleton_method(:_typelizer_model_name) { model } end |
#typelize_meta(**attributes) ⇒ Object
70 71 72 |
# File 'lib/typelizer/dsl.rb', line 70 def (**attributes) assign_type_information(:_typelizer_meta_attributes, attributes) end |
#typelizer_config(&block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/typelizer/dsl.rb', line 22 def typelizer_config(&block) # Lazily initializes and memoizes the hash for local overrides at the class level. # This ensures that all subsequent DSL calls for this specific serializer class # modify the same single hash, allowing settings to be accumulated @serializer_overrides ||= {} @config_layer ||= SerializerConfigLayer.new(@serializer_overrides) @config_layer.instance_eval(&block) if block @config_layer end |