Class: Typelizer::Config
- Inherits:
-
Struct
- Object
- Struct
- Typelizer::Config
- Defined in:
- lib/typelizer/config.rb,
lib/typelizer/config.rb
Overview
Immutable configuration object for a single writer
Use .build to construct from defaults, and #with_overrides to copy with overrides.
Instance Attribute Summary collapse
-
#associations_strategy ⇒ Object
Returns the value of attribute associations_strategy.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#enum_runtime ⇒ Object
Returns the value of attribute enum_runtime.
-
#filename_mapper ⇒ Object
Returns the value of attribute filename_mapper.
-
#imports_sort_order ⇒ Object
Returns the value of attribute imports_sort_order.
-
#inheritance_strategy ⇒ Object
Returns the value of attribute inheritance_strategy.
-
#model_plugin ⇒ Object
Returns the value of attribute model_plugin.
-
#null_strategy ⇒ Object
Returns the value of attribute null_strategy.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#plugin_configs ⇒ Object
Returns the value of attribute plugin_configs.
-
#prefer_double_quotes ⇒ Object
Returns the value of attribute prefer_double_quotes.
-
#properties_sort_order ⇒ Object
Returns the value of attribute properties_sort_order.
-
#properties_transformer ⇒ Object
Returns the value of attribute properties_transformer.
-
#reject_class ⇒ Object
Returns the value of attribute reject_class.
-
#serializer_model_mapper ⇒ Object
Returns the value of attribute serializer_model_mapper.
-
#serializer_name_mapper ⇒ Object
Returns the value of attribute serializer_name_mapper.
-
#serializer_plugin ⇒ Object
Returns the value of attribute serializer_plugin.
-
#type_mapping ⇒ Object
Returns the value of attribute type_mapping.
-
#types_global ⇒ Object
Returns the value of attribute types_global.
-
#types_import_path ⇒ Object
Returns the value of attribute types_import_path.
-
#verbatim_module_syntax ⇒ Object
Returns the value of attribute verbatim_module_syntax.
Class Method Summary collapse
- .build(**overrides) ⇒ Object
- .default_output_dir ⇒ Object
-
.defaults ⇒ Object
Returns library defaults (built-in) for building a Config.
Instance Method Summary collapse
Instance Attribute Details
#associations_strategy ⇒ Object
Returns the value of attribute associations_strategy
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def associations_strategy @associations_strategy end |
#comments ⇒ Object
Returns the value of attribute comments
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def comments @comments end |
#enum_runtime ⇒ Object
Returns the value of attribute enum_runtime
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def enum_runtime @enum_runtime end |
#filename_mapper ⇒ Object
Returns the value of attribute filename_mapper
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def filename_mapper @filename_mapper end |
#imports_sort_order ⇒ Object
Returns the value of attribute imports_sort_order
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def imports_sort_order @imports_sort_order end |
#inheritance_strategy ⇒ Object
Returns the value of attribute inheritance_strategy
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def inheritance_strategy @inheritance_strategy end |
#model_plugin ⇒ Object
Returns the value of attribute model_plugin
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def model_plugin @model_plugin end |
#null_strategy ⇒ Object
Returns the value of attribute null_strategy
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def null_strategy @null_strategy end |
#output_dir ⇒ Object
Returns the value of attribute output_dir
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def output_dir @output_dir end |
#plugin_configs ⇒ Object
Returns the value of attribute plugin_configs
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def plugin_configs @plugin_configs end |
#prefer_double_quotes ⇒ Object
Returns the value of attribute prefer_double_quotes
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def prefer_double_quotes @prefer_double_quotes end |
#properties_sort_order ⇒ Object
Returns the value of attribute properties_sort_order
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def properties_sort_order @properties_sort_order end |
#properties_transformer ⇒ Object
Returns the value of attribute properties_transformer
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def properties_transformer @properties_transformer end |
#reject_class ⇒ Object
Returns the value of attribute reject_class
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def reject_class @reject_class end |
#serializer_model_mapper ⇒ Object
Returns the value of attribute serializer_model_mapper
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def serializer_model_mapper @serializer_model_mapper end |
#serializer_name_mapper ⇒ Object
Returns the value of attribute serializer_name_mapper
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def serializer_name_mapper @serializer_name_mapper end |
#serializer_plugin ⇒ Object
Returns the value of attribute serializer_plugin
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def serializer_plugin @serializer_plugin end |
#type_mapping ⇒ Object
Returns the value of attribute type_mapping
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def type_mapping @type_mapping end |
#types_global ⇒ Object
Returns the value of attribute types_global
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def types_global @types_global end |
#types_import_path ⇒ Object
Returns the value of attribute types_import_path
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def types_import_path @types_import_path end |
#verbatim_module_syntax ⇒ Object
Returns the value of attribute verbatim_module_syntax
63 64 65 |
# File 'lib/typelizer/config.rb', line 63 def verbatim_module_syntax @verbatim_module_syntax end |
Class Method Details
.build(**overrides) ⇒ Object
136 137 138 |
# File 'lib/typelizer/config.rb', line 136 def self.build(**overrides) new(**defaults.merge(overrides)) end |
.default_output_dir ⇒ Object
140 141 142 143 144 145 |
# File 'lib/typelizer/config.rb', line 140 def self.default_output_dir root_path = defined?(Rails) ? Rails.root : Pathname.pwd js_root = defined?(ViteRuby) ? ViteRuby.config.source_code_dir : "app/javascript" root_path.join(js_root, "types/serializers") end |
.defaults ⇒ Object
Returns library defaults (built-in) for building a Config. This method creates a fresh Hash each time to avoid sharing mutable state across builds
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/typelizer/config.rb', line 95 def self.defaults { serializer_name_mapper: lambda do |serializer| name = serializer.name.to_s return name if name.empty? # remove only the end of the line name.sub(/(Serializer|Resource)\z/, "") end, filename_mapper: nil, serializer_model_mapper: lambda do |serializer| base_class = serializer_name_mapper.call(serializer) Object.const_get(base_class) if Object.const_defined?(base_class) end, model_plugin: ModelPlugins::Auto, serializer_plugin: SerializerPlugins::Auto, plugin_configs: {}.freeze, type_mapping: TYPE_MAPPING, null_strategy: :nullable, inheritance_strategy: :none, associations_strategy: :database, reject_class: ->(serializer:) { false }, comments: false, prefer_double_quotes: false, enum_runtime: false, output_dir: -> { default_output_dir }, types_import_path: "@/types", types_global: DEFAULT_TYPES_GLOBAL, properties_transformer: nil, properties_sort_order: :none, imports_sort_order: :none, verbatim_module_syntax: false } end |
Instance Method Details
#with_overrides(**overrides) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/typelizer/config.rb', line 147 def with_overrides(**overrides) props = to_h props.merge!(overrides) unless overrides.empty? self.class.new(**props) end |