Sha256: 15c663f0c7a19ec02ffa37b50160810151d6884226a15b91bc034351720792e4

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true
module Geoblacklight
  module Relation
    class RelationResponse
      attr_reader :search_id, :link_id
      def initialize(id, repository)
        @link_id = id
        @search_id = RSolr.solr_escape(id)
        @repository = repository
      end

      def method_missing(method, *args, &block)
        if Settings.RELATIONSHIPS_SHOWN.key?(method)
          field = Settings.RELATIONSHIPS_SHOWN[method].field
          query_type = query_type(Settings.RELATIONSHIPS_SHOWN[method])
          @results = query_type.new(@search_id, field, @repository).results
        else
          super
        end
      end

      def respond_to_missing?(method_name, *args)
        Settings.RELATIONSHIPS_SHOWN.key?(method_name) or super
      end

      private

      def query_type(option)
        case option.query_type
        when 'ancestors'
          Geoblacklight::Relation::Ancestors
        when 'descendants'
          Geoblacklight::Relation::Descendants
        else
          fail ArgumentError, "Bad RelationResponse query_type: #{option.query_type}. Only 'ancestors' or 'descendants' is allowed."
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
geoblacklight-4.0.0 lib/geoblacklight/relation/relation_response.rb
geoblacklight-4.0.0.pre.rc3 lib/geoblacklight/relation/relation_response.rb
geoblacklight-4.0.0.pre.rc2 lib/geoblacklight/relation/relation_response.rb
geoblacklight-4.0.0.pre.rc1 lib/geoblacklight/relation/relation_response.rb
geoblacklight-4.0.0.pre.alpha.3 lib/geoblacklight/relation/relation_response.rb
geoblacklight-4.0.0.pre.alpha.2 lib/geoblacklight/relation/relation_response.rb
geoblacklight-4.0.0.pre.alpha.1 lib/geoblacklight/relation/relation_response.rb
geoblacklight-4.0.0.pre.alpha lib/geoblacklight/relation/relation_response.rb