Sha256: 8211b5add5feef1e9e727fe2915ddfa6802038e1c1359610ea7809e9e1c735a2

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module ActiveFedora::Aggregation
  module BaseExtension
    extend ActiveSupport::Concern

    def ordered_by
      ordered_by_ids.lazy.map{ |x| ActiveFedora::Base.find(x) }
    end

    private

      def ordered_by_ids
        if id.present?
          ActiveFedora::SolrService.query("{!join from=proxy_in_ssi to=id}ordered_targets_ssim:#{id}")
            .map{|x| x["id"]}
        else
          []
        end
      end

    module ClassMethods
      ##
      # Allows ordering of an association
      # @example
      #   class Image < ActiveFedora::Base
      #     contains :list_resource, class_name:
      #       "ActiveFedora::Aggregation::ListSource"
      #     orders :generic_files, through: :list_resource
      #   end
      def orders(name, options={})
        ActiveFedora::Orders::Builder.build(self, name, options)
      end

      ##
      # Convenience method for building an ordered aggregation.
      # @example
      #   class Image < ActiveFedora::Base
      #     ordered_aggregation :members, through: :list_source
      #   end
      def ordered_aggregation(name, options={})
        ActiveFedora::Orders::AggregationBuilder.build(self, name, options)
      end

      ##
      # Create an association filter on the class
      # @example
      #   class Image < ActiveFedora::Base
      #     aggregates :generic_files
      #     filters_association :generic_files, as: :large_files, condition: :big_file?
      #   end
      def filters_association(extending_from, options={})
        name = options.delete(:as)
        ActiveFedora::Filter::Builder.build(self, name, options.merge(extending_from: extending_from))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activefedora-aggregation-0.10.0 lib/active_fedora/aggregation/base_extension.rb