Sha256: f46bcc1eb706f23761d32c437eb627a729781cb5afb1f8d71c5365b72499b2f1

Contents?: true

Size: 970 Bytes

Versions: 3

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true
module SpeedyAF
  module OrderedAggregationIndex
    extend ActiveSupport::Concern

    module ClassMethods
      def indexed_ordered_aggregation(name)
        target_class = reflections[name].class_name
        contains_key = reflections[:"ordered_#{name.to_s.singularize}_proxies"].options[:through]
        mixin = generated_association_methods
        mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
          def indexed_#{name}
            ids = self.indexed_#{name.to_s.singularize}_ids
            ids.lazy.collect { |id| #{target_class}.find(id) }
          end

          def indexed_#{name.to_s.singularize}_ids
            return [] unless persisted?
            docs = ActiveFedora::SolrService.query "id: \#{self.id}/#{contains_key}", rows: 1
            return [] if docs.empty? or docs.first['ordered_targets_ssim'].nil?
            docs.first['ordered_targets_ssim']
          end
        CODE
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
speedy-af-0.4.0 lib/speedy_af/ordered_aggregation_index.rb
speedy-af-0.3.0 lib/speedy_af/ordered_aggregation_index.rb
speedy-af-0.2.0 lib/speedy_af/ordered_aggregation_index.rb