Sha256: 61481f3a852e7060946c86ec14e710b54280d1fa0511ce6dc4d5e87f4e515516

Contents?: true

Size: 1.11 KB

Versions: 37

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Decidim
  module Core
    # 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
    class ComponentFinderBase
      attr_reader :model_class

      def initialize(model_class:)
        @model_class = model_class
      end

      def call(component, args, _ctx)
        @query = { component: component }
        args.keys.each do |key|
          @query[key] = args[key]
        end
        query_scope.find_by(@query)
      end

      # By default, any model in its defaul scope
      # Particular implementations may restrict this by adding
      # additional constrains
      def query_scope
        model_class
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.8 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.7 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.6 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.10 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.9 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.5 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.8 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.4 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.3 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.7 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.5 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.2 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.1 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.4 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.0 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.3 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.0.rc2 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.27.0.rc1 lib/decidim/api/functions/component_finder_base.rb
decidim-core-0.26.2 lib/decidim/api/functions/component_finder_base.rb