Module: SvelteOnRails::ActiveRecordRelationExtensions

Defined in:
lib/svelte_on_rails/active_record_extensions.rb

Instance Method Summary collapse

Instance Method Details

#to_svelte(*attributes, **associations) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/svelte_on_rails/active_record_extensions.rb', line 53

def to_svelte(*attributes, **associations)
  conf = SvelteOnRails::Configuration.instance
  conf.to_svelte_benchmark_log("Relation extracted") do

    cache_key = (I18n.locale.to_s + self.name + attributes.to_s + associations.to_s).hash

    cl = SvelteOnRails::Lib::ToSvelteValues
    tsl = SvelteOnRails::Lib::ToSvelteSchema.instance
    tnl = SvelteOnRails::Lib::ToSvelteTranslations.instance

    data = cl.extract_values(self, attributes, associations)

    models, schema = tsl.extract_schema(self.klass, attributes, associations, cache_key)
    translations = tnl.all_cached_translations(I18n.locale, :to_svelte_props, models, self.klass)

    { 'data' => data }.merge(schema).merge(translations)
  end
end