Sha256: 5cb9d7acdc522d01ca202b494108673b0812e9a573abe2c4bb30a8e3c8f1f675

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

module ActsAsFavoritor
    module FavoritorLib

        private

        DEFAULT_PARENTS = [ApplicationRecord, ActiveRecord::Base]

        # Retrieves the parent class name if using STI.
        def parent_class_name obj
            unless parent_classes.include? obj.class.superclass
                return obj.class.base_class.name
            end
            obj.class.name
        end

        def apply_options_to_scope scope, options = {}
            if options.has_key? :limit
                scope = scope.limit options[:limit]
            end
            if options.has_key? :includes
                scope = scope.includes options[:includes]
            end
            if options.has_key? :joins
                scope = scope.joins options[:joins]
            end
            if options.has_key? :where
                scope = scope.where options[:where]
            end
            if options.has_key? :order
                scope = scope.order options[:order]
            end
            scope
        end

        def parent_classes
            return DEFAULT_PARENTS unless ActsAsFavoritor.custom_parent_classes

            ActiveSupport::Deprecation.warn('Setting custom parent classes is deprecated and will be removed in future versions.')
            ActsAsFavoritor.custom_parent_classes + DEFAULT_PARENTS
        end

    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_favoritor-1.0.2 lib/acts_as_favoritor/favoritor_lib.rb
acts_as_favoritor-1.0.1 lib/acts_as_favoritor/favoritor_lib.rb