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.
-
#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
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def associations_strategy @associations_strategy end |
#comments ⇒ Object
Returns the value of attribute comments
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def comments @comments end |
#filename_mapper ⇒ Object
Returns the value of attribute filename_mapper
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def filename_mapper @filename_mapper end |
#imports_sort_order ⇒ Object
Returns the value of attribute imports_sort_order
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def imports_sort_order @imports_sort_order end |
#inheritance_strategy ⇒ Object
Returns the value of attribute inheritance_strategy
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def inheritance_strategy @inheritance_strategy end |
#model_plugin ⇒ Object
Returns the value of attribute model_plugin
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def model_plugin @model_plugin end |
#null_strategy ⇒ Object
Returns the value of attribute null_strategy
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def null_strategy @null_strategy end |
#output_dir ⇒ Object
Returns the value of attribute output_dir
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def output_dir @output_dir end |
#plugin_configs ⇒ Object
Returns the value of attribute plugin_configs
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def plugin_configs @plugin_configs end |
#prefer_double_quotes ⇒ Object
Returns the value of attribute prefer_double_quotes
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def prefer_double_quotes @prefer_double_quotes end |
#properties_sort_order ⇒ Object
Returns the value of attribute properties_sort_order
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def properties_sort_order @properties_sort_order end |
#properties_transformer ⇒ Object
Returns the value of attribute properties_transformer
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def properties_transformer @properties_transformer end |
#reject_class ⇒ Object
Returns the value of attribute reject_class
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def reject_class @reject_class end |
#serializer_model_mapper ⇒ Object
Returns the value of attribute serializer_model_mapper
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def serializer_model_mapper @serializer_model_mapper end |
#serializer_name_mapper ⇒ Object
Returns the value of attribute serializer_name_mapper
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def serializer_name_mapper @serializer_name_mapper end |
#serializer_plugin ⇒ Object
Returns the value of attribute serializer_plugin
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def serializer_plugin @serializer_plugin end |
#type_mapping ⇒ Object
Returns the value of attribute type_mapping
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def type_mapping @type_mapping end |
#types_global ⇒ Object
Returns the value of attribute types_global
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def types_global @types_global end |
#types_import_path ⇒ Object
Returns the value of attribute types_import_path
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def types_import_path @types_import_path end |
#verbatim_module_syntax ⇒ Object
Returns the value of attribute verbatim_module_syntax
58 59 60 |
# File 'lib/typelizer/config.rb', line 58 def verbatim_module_syntax @verbatim_module_syntax end |
Class Method Details
.build(**overrides) ⇒ Object
129 130 131 |
# File 'lib/typelizer/config.rb', line 129 def self.build(**overrides) new(**defaults.merge(overrides)) end |
.default_output_dir ⇒ Object
133 134 135 136 137 138 |
# File 'lib/typelizer/config.rb', line 133 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
89 90 91 92 93 94 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 |
# File 'lib/typelizer/config.rb', line 89 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, 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
140 141 142 143 144 145 |
# File 'lib/typelizer/config.rb', line 140 def with_overrides(**overrides) props = to_h props.merge!(overrides) unless overrides.empty? self.class.new(**props) end |