Sha256: efb901439b4224071287771ee7d2c746387fe3e8c0fd1231bc3409b58ef9b959

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

module ActsAsFerret

  # Include this module to use acts_as_ferret with model classes 
  # not based on ActiveRecord. 
  #
  # Implement the find_for_id(id) class method in your model class in
  # order to make search work.
  module WithoutAR
    def self.included(target)
      target.extend ClassMethods
      target.extend ActsAsFerret::ActMethods
      target.send :include, InstanceMethods
    end

    module ClassMethods
      def logger
        RAILS_DEFAULT_LOGGER
      end
      def table_name
        self.name.underscore
      end
      def primary_key
        'id'
      end
      def find(what, args = {})
        case what
        when :all
          ids = args[:conditions][1]
          ids.map { |id| find id }
        else
          find_for_id what
        end
      end
      def find_for_id(id)
        raise NotImplementedError.new("implement find_for_id in class #{self.name}")
      end
      def count
        0
      end
    end

    module InstanceMethods
      def logger
        self.class.logger
      end
      def new_record?
        false
      end
    end
  end
        
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
cehoffman-acts_as_ferret-0.4.4 lib/without_ar.rb
jkraemer-acts_as_ferret-0.4.4 lib/without_ar.rb
acts_as_ferret-0.5.4 lib/acts_as_ferret/without_ar.rb
acts_as_ferret-0.5.3 lib/acts_as_ferret/without_ar.rb
watson-acts_as_ferret-0.4.8.2 lib/without_ar.rb
acts_as_ferret-0.5.2 lib/acts_as_ferret/without_ar.rb
acts_as_ferret-0.4.8.2 lib/without_ar.rb
acts_as_ferret-0.4.8.1 lib/without_ar.rb
acts_as_ferret-0.5.1 lib/acts_as_ferret/without_ar.rb
acts_as_ferret-0.5 lib/acts_as_ferret/without_ar.rb
acts_as_ferret-0.4.8.rails3 lib/without_ar.rb
acts_as_ferret-0.4.8 lib/without_ar.rb
acts_as_ferret-0.4.7 lib/without_ar.rb
acts_as_ferret-0.4.6 lib/without_ar.rb
acts_as_ferret-0.4.4 lib/without_ar.rb