Sha256: 2c048c74ae3e1e3fd3d1d553782dca53c531f253abf3dae2c2efedeccda66bd1

Contents?: true

Size: 1.14 KB

Versions: 38

Compression:

Stored size: 1.14 KB

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(to_hash)
    end

    def merge(new_hash)
      self.class.new(to_hash.merge(new_hash))
    end

    def to_hash
      @hash.deep_dup
    end

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

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

      def as(*args)
        @term = args.last.is_a?(Hash) ? args.pop : {}
        @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

38 entries across 38 versions & 1 rubygems

Version Path
active-fedora-15.0.1 lib/active_fedora/indexing/map.rb
active-fedora-15.0.0 lib/active_fedora/indexing/map.rb
active-fedora-14.0.1 lib/active_fedora/indexing/map.rb
active-fedora-14.0.0 lib/active_fedora/indexing/map.rb
active-fedora-13.3.0 lib/active_fedora/indexing/map.rb
active-fedora-12.2.4 lib/active_fedora/indexing/map.rb
active-fedora-13.2.7 lib/active_fedora/indexing/map.rb
active-fedora-13.2.5 lib/active_fedora/indexing/map.rb
active-fedora-13.2.4 lib/active_fedora/indexing/map.rb
active-fedora-12.2.3 lib/active_fedora/indexing/map.rb
active-fedora-13.2.3 lib/active_fedora/indexing/map.rb
active-fedora-13.2.2 lib/active_fedora/indexing/map.rb
active-fedora-13.2.0 lib/active_fedora/indexing/map.rb
active-fedora-13.1.3 lib/active_fedora/indexing/map.rb
active-fedora-11.5.6 lib/active_fedora/indexing/map.rb
active-fedora-12.2.2 lib/active_fedora/indexing/map.rb
active-fedora-11.2.1 lib/active_fedora/indexing/map.rb
active-fedora-12.2.1 lib/active_fedora/indexing/map.rb
active-fedora-12.0.3 lib/active_fedora/indexing/map.rb
active-fedora-11.5.5 lib/active_fedora/indexing/map.rb