Module: Jat::Plugins::BasePreloads::AttributeMethods
- Defined in:
- lib/jat/plugins/base/base_preloads/base_preloads.rb
Constant Summary collapse
- NULL_PRELOADS =
[nil, [].freeze].freeze
Instance Method Summary collapse
-
#get_preloads_with_path ⇒ Object
When provided multiple values in preloads, such as { user: [:profile] }, we don’t know which entity is main (:user or :profile in this example) but we need to know main value to add nested preloads to it.
- #preloads ⇒ Object
- #preloads_path ⇒ Object
Instance Method Details
#get_preloads_with_path ⇒ Object
When provided multiple values in preloads, such as { user: [:profile] }, we don’t know which entity is main (:user or :profile in this example) but we need to know main value to add nested preloads to it. User can specify main preloaded entity by adding “!” suffix ({ user!: [:profile] } for example), otherwise the latest key will be considered main.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jat/plugins/base/base_preloads/base_preloads.rb', line 40 def get_preloads_with_path preloads_provided = opts.key?(:preload) preloads = if preloads_provided opts[:preload] elsif relation? key end # Nulls and empty hash differs as we can preload nested results to # empty hash, but we will skip nested preloading if null or false provided return NULL_PRELOADS if preloads_provided && !preloads preloads = FormatUserPreloads.to_hash(preloads) preloads, path = PreloadsWithPath.call(preloads) [EnumDeepFreeze.call(preloads), path.freeze] end |
#preloads ⇒ Object
21 22 23 24 25 26 |
# File 'lib/jat/plugins/base/base_preloads/base_preloads.rb', line 21 def preloads return @preloads if defined?(@preloads) @preloads, @preloads_path = get_preloads_with_path @preloads end |
#preloads_path ⇒ Object
28 29 30 31 32 33 |
# File 'lib/jat/plugins/base/base_preloads/base_preloads.rb', line 28 def preloads_path return @preloads_path if defined?(@preloads_path) @preloads, @preloads_path = get_preloads_with_path @preloads_path end |