Class: LcpRuby::Presenter::IncludesResolver::AssociationDependency
- Inherits:
-
Object
- Object
- LcpRuby::Presenter::IncludesResolver::AssociationDependency
- Defined in:
- lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb
Overview
Value object representing a single association that needs eager loading.
Constant Summary collapse
- VALID_REASONS =
%i[display query].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
-
#association_name ⇒ Object
Top-level association name regardless of nesting.
- #display? ⇒ Boolean
-
#initialize(path:, reason:) ⇒ AssociationDependency
constructor
A new instance of AssociationDependency.
- #nested? ⇒ Boolean
- #query? ⇒ Boolean
Constructor Details
#initialize(path:, reason:) ⇒ AssociationDependency
Returns a new instance of AssociationDependency.
16 17 18 19 20 21 |
# File 'lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb', line 16 def initialize(path:, reason:) @path = path @reason = reason.to_sym validate! end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb', line 14 def path @path end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
14 15 16 |
# File 'lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb', line 14 def reason @reason end |
Instance Method Details
#association_name ⇒ Object
Top-level association name regardless of nesting. :company from either :company or { company: :industry }
25 26 27 28 29 30 31 |
# File 'lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb', line 25 def association_name case path when Symbol then path when Hash then path.keys.first else raise ArgumentError, "Invalid path type: #{path.class}" end end |
#display? ⇒ Boolean
41 42 43 |
# File 'lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb', line 41 def display? reason == :display end |
#nested? ⇒ Boolean
33 34 35 |
# File 'lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb', line 33 def nested? path.is_a?(Hash) end |
#query? ⇒ Boolean
37 38 39 |
# File 'lib/lcp_ruby/presenter/includes_resolver/association_dependency.rb', line 37 def query? reason == :query end |