Class: LcpRuby::Presenter::IncludesResolver::DependencyCollector
- Inherits:
-
Object
- Object
- LcpRuby::Presenter::IncludesResolver::DependencyCollector
- Defined in:
- lib/lcp_ruby/presenter/includes_resolver/dependency_collector.rb
Overview
Gathers AssociationDependency objects from various sources: presenter metadata, sort params, search fields, and manual YAML config.
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
Instance Method Summary collapse
-
#from_manual(config) ⇒ Object
Read manual includes/eager_load from presenter config hash.
-
#from_presenter(presenter_def, model_def, context) ⇒ Object
Auto-detect associations from presenter metadata based on context.
-
#from_search(fields, model_def) ⇒ Object
Parse dot-notation searchable fields into query dependencies.
-
#from_sort(field, model_def) ⇒ Object
Parse dot-notation sort field into a query dependency.
-
#initialize ⇒ DependencyCollector
constructor
A new instance of DependencyCollector.
Constructor Details
#initialize ⇒ DependencyCollector
Returns a new instance of DependencyCollector.
9 10 11 |
# File 'lib/lcp_ruby/presenter/includes_resolver/dependency_collector.rb', line 9 def initialize @dependencies = [] end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
7 8 9 |
# File 'lib/lcp_ruby/presenter/includes_resolver/dependency_collector.rb', line 7 def dependencies @dependencies end |
Instance Method Details
#from_manual(config) ⇒ Object
Read manual includes/eager_load from presenter config hash. includes -> :display, eager_load -> :query
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lcp_ruby/presenter/includes_resolver/dependency_collector.rb', line 70 def from_manual(config) return unless config.is_a?(Hash) (config["includes"] || []).each do |entry| add_dependency(path: normalize_manual_path(entry), reason: :display) end (config["eager_load"] || []).each do |entry| add_dependency(path: normalize_manual_path(entry), reason: :query) end end |
#from_presenter(presenter_def, model_def, context) ⇒ Object
Auto-detect associations from presenter metadata based on context.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lcp_ruby/presenter/includes_resolver/dependency_collector.rb', line 18 def from_presenter(presenter_def, model_def, context) case context when :index then collect_index_deps(presenter_def, model_def) when :show then collect_show_deps(presenter_def, model_def) when :form then collect_form_deps(presenter_def, model_def) end # link:/link_through: on show fields and index columns may require # an extra eager-load when the linked association is not already # referenced via a dot-path. Form context opts out entirely (V13). collect_link_deps(presenter_def, model_def, context) unless context == :form end |
#from_search(fields, model_def) ⇒ Object
Parse dot-notation searchable fields into query dependencies.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/lcp_ruby/presenter/includes_resolver/dependency_collector.rb', line 51 def from_search(fields, model_def) return unless fields.is_a?(Array) fields.each do |field| next unless field.to_s.include?(".") parts = field.to_s.split(".") assoc_name = parts.first assoc = find_association(model_def, assoc_name) next unless assoc add_dependency(path: assoc_name.to_sym, reason: :query) end end |
#from_sort(field, model_def) ⇒ Object
Parse dot-notation sort field into a query dependency. e.g. “company.name” -> :query on :company
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lcp_ruby/presenter/includes_resolver/dependency_collector.rb', line 36 def from_sort(field, model_def) return unless field.to_s.include?(".") parts = field.to_s.split(".") assoc_name = parts.first assoc = find_association(model_def, assoc_name) return unless assoc add_dependency(path: assoc_name.to_sym, reason: :query) end |