Sha256: 037237a52615aba1608f5f45c587a5b2a289eff638b7cf591dd60a6547bf131c

Contents?: true

Size: 962 Bytes

Versions: 6

Compression:

Stored size: 962 Bytes

Contents

require 'forwardable'
module ActiveFedora::Indexing
  # This is a description of how properties should map to indexing strategies
  #  e.g. 'creator_name' => <IndexObject behaviors=[:stored_searchable, :facetable]>
  class Map
    extend Forwardable
    def_delegators :@hash, :[], :[]=, :each, :keys

    def initialize(hash = {})
      @hash = hash
    end

    def dup
      self.class.new(@hash.deep_dup)
    end

    # this enables a cleaner API for solr integration
    class IndexObject
      attr_accessor :data_type, :behaviors
      attr_reader :key

      def initialize(name, &_block)
        @behaviors = []
        @data_type = :string
        @key = name
        yield self if block_given?
      end

      def as(*args)
        @behaviors = args
      end

      def type(sym)
        @data_type = sym
      end

      def dup
        self.class.new(@key) do |idx|
          idx.behaviors = @behaviors.dup
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active-fedora-9.7.3 lib/active_fedora/indexing/map.rb
active-fedora-9.7.2 lib/active_fedora/indexing/map.rb
active-fedora-9.7.1 lib/active_fedora/indexing/map.rb
active-fedora-9.7.0 lib/active_fedora/indexing/map.rb
active-fedora-9.6.2 lib/active_fedora/indexing/map.rb
active-fedora-9.6.1 lib/active_fedora/indexing/map.rb