Sha256: 5fcc8a47a4e9c3668a957a8f150d19041c2a5d9a74640242d007d34efc909835
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module ActsAsFavoritor module FavoritorLib private DEFAULT_PARENTS = [ApplicationRecord, ActiveRecord::Base].freeze # 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 = {}) scope = scope.limit(options[:limit]) if options.key?(:limit) scope = scope.includes(options[:includes]) if options.key?(:includes) scope = scope.joins(options[:joins]) if options.key?(:joins) scope = scope.where(options[:where]) if options.key?(:where) scope = scope.order(options[:order]) if options.key?(:order) scope end def parent_classes DEFAULT_PARENTS end def validate_scopes(method, options = {}) options[:scope] ||= [ActsAsFavoritor.configuration.default_scope] if options[:scope].size > 1 options[:multiple_scopes] = true else options[:multiple_scopes] = false options[:scope] = options[:scope][0] end if options.key? :parameter parameter = options[:parameter] options.delete :parameter send(method, parameter, options) else send(method, options) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
acts_as_favoritor-2.1.1 | lib/acts_as_favoritor/favoritor_lib.rb |
acts_as_favoritor-2.1.0 | lib/acts_as_favoritor/favoritor_lib.rb |