Module: SvelteOnRails::ActiveRecordExtensions
- Defined in:
- lib/svelte_on_rails/active_record_extensions.rb
Instance Method Summary collapse
-
#to_svelte(*attributes, **associations) ⇒ Object
Returns a hash of attributes, methods, and associations formatted for Svelte components.
Instance Method Details
#to_svelte(*attributes, **associations) ⇒ Object
Returns a hash of attributes, methods, and associations formatted for Svelte components
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/svelte_on_rails/active_record_extensions.rb', line 7 def to_svelte(*attributes, **associations) conf = SvelteOnRails::Configuration.instance conf.to_svelte_benchmark_log("Record extracted") do cache_key = (I18n.locale.to_s + self.class.name + attributes.to_s + associations.to_s).hash tsv = SvelteOnRails::Lib::ToSvelteValues tsl = SvelteOnRails::Lib::ToSvelteSchema.instance tnl = SvelteOnRails::Lib::ToSvelteTranslations.instance values = tsv.extract_values(self, attributes, associations) models, schema = tsl.extract_schema(self.class, attributes, associations, cache_key) translations = tnl.all_cached_translations(I18n.locale, :to_svelte_props, models, self.class) values.merge(schema).merge(translations) end end |