Sha256: c9bd2883163212f30ff0b35379f732e934f032ba19fd4575eddcfd3c56089e8d
Contents?: true
Size: 715 Bytes
Versions: 1
Compression:
Stored size: 715 Bytes
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 DEFAULT_PARENTS.include? obj.class.superclass return obj.class.base_class.name end obj.class.name end def build_result_for_scopes(scopes) return if scopes.empty? scopes = sanitized_scopes(scopes) result = scopes.map { |scope| [scope, yield(scope)] }.to_h return result[scopes.first] if scopes.size == 1 result end def sanitized_scopes(scopes) scopes.map(&:to_sym) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_favoritor-3.0.0 | lib/acts_as_favoritor/favoritor_lib.rb |