Class: Decidim::Core::ComponentFinderBase
- Inherits:
-
GraphQL::Function
- Object
- GraphQL::Function
- Decidim::Core::ComponentFinderBase
- Defined in:
- app/functions/decidim/core/component_finder_base.rb
Overview
An abstract class with the logic for the GraphQL endpoint for a single component to be searchable. Normal components (such as Proposal) can inherit from this class and just add the needed search arguments
Usually something like:
class ProposalFinderHelper < Decidim::Core::ComponentFinderBase
argument :id, !types.ID, "The ID of the proposal"
end
For an example check decidim-proposals/app/types/decidim/proposals/proposals_type.rb
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
- #call(component, args, _ctx) ⇒ Object
-
#initialize(model_class:) ⇒ ComponentFinderBase
constructor
A new instance of ComponentFinderBase.
-
#query_scope ⇒ Object
By default, any model in its defaul scope Particular implementations may restrict this by adding additional constrains.
Constructor Details
#initialize(model_class:) ⇒ ComponentFinderBase
Returns a new instance of ComponentFinderBase.
20 21 22 |
# File 'app/functions/decidim/core/component_finder_base.rb', line 20 def initialize(model_class:) @model_class = model_class end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
18 19 20 |
# File 'app/functions/decidim/core/component_finder_base.rb', line 18 def model_class @model_class end |
Instance Method Details
#call(component, args, _ctx) ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/functions/decidim/core/component_finder_base.rb', line 24 def call(component, args, _ctx) @query = { component: component } args.keys.each do |key| @query[key] = args[key] end query_scope.find_by(@query) end |
#query_scope ⇒ Object
By default, any model in its defaul scope Particular implementations may restrict this by adding additional constrains
35 36 37 |
# File 'app/functions/decidim/core/component_finder_base.rb', line 35 def query_scope model_class end |