Sha256: 435734291783f4bff115984b0d3d5f72e1eff50c319ee9e84e0de4abf3409158

Contents?: true

Size: 1.27 KB

Versions: 23

Compression:

Stored size: 1.27 KB

Contents

module Sunspot #:nodoc:
  module Rails #:nodoc:
    # 
    # This module provides Sunspot Adapter implementations for ActiveRecord
    # models.
    #
    module Adapters
      class ActiveRecordInstanceAdapter < Sunspot::Adapters::InstanceAdapter
        # 
        # Return the primary key for the adapted instance
        #
        # ==== Returns
        # 
        # Integer:: Database ID of model
        #
        def id
          @instance.id
        end
      end

      class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
        # 
        # Get one ActiveRecord instance out of the database by ID
        #
        # ==== Parameters
        #
        # id<String>:: Database ID of model to retreive
        #
        # ==== Returns
        #
        # ActiveRecord::Base:: ActiveRecord model
        # 
        def load(id)
          @clazz.find(id.to_i)
        end

        # 
        # Get a collection of ActiveRecord instances out of the database by ID
        #
        # ==== Parameters
        #
        # ids<Array>:: Database IDs of models to retrieve
        #
        # ==== Returns
        #
        # Array:: Collection of ActiveRecord models
        #
        def load_all(ids)
          @clazz.find(ids.map { |id| id.to_i })
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 10 rubygems

Version Path
adamsalter-sunspot_rails-0.10.4 lib/sunspot/rails/adapters.rb
adamsalter-sunspot_rails-0.10.5 lib/sunspot/rails/adapters.rb
benjaminkrause-sunspot_rails-0.10.5 lib/sunspot/rails/adapters.rb
bsy-sunspot_rails-0.10.4 lib/sunspot/rails/adapters.rb
collectiveidea-sunspot_rails-0.10.5 lib/sunspot/rails/adapters.rb
collectiveidea-sunspot_rails-0.10.6 lib/sunspot/rails/adapters.rb
kristopher-sunspot_rails-0.10.6 lib/sunspot/rails/adapters.rb
kuahyeow-sunspot_rails-0.10.5 lib/sunspot/rails/adapters.rb
outoftime-sunspot_rails-0.10.2 lib/sunspot/rails/adapters.rb
outoftime-sunspot_rails-0.10.3 lib/sunspot/rails/adapters.rb
outoftime-sunspot_rails-0.10.4 lib/sunspot/rails/adapters.rb
outoftime-sunspot_rails-0.10.5 lib/sunspot/rails/adapters.rb
ssoroka-sunspot_rails-0.10.5 lib/sunspot/rails/adapters.rb
ssoroka-sunspot_rails-0.10.6 lib/sunspot/rails/adapters.rb
goldstar-sunspot_rails-0.10.6.3 lib/sunspot/rails/adapters.rb
goldstar-sunspot_rails-0.10.6.1 lib/sunspot/rails/adapters.rb
sunspot_rails-0.10.9 lib/sunspot/rails/adapters.rb
kuahyeow-sunspot_rails-0.10.7 lib/sunspot/rails/adapters.rb
kuahyeow-sunspot_rails-0.10.6 lib/sunspot/rails/adapters.rb
sunspot_rails-0.10.8 lib/sunspot/rails/adapters.rb