lib/is_reviewable/support.rb
# Shortcut method for generating conditions hash for polymorphic belongs_to-associations.
#
Shortcut method for generating conditions hash for polymorphic belongs_to-associations.
Shortcut method for generating conditions hash for polymorphic belongs_to - associations .
def polymorphic_conditions_for(object_or_type, field, *match)
      match = [:id, :type] if match.blank?
      returning({}) do |conditions|
        conditions.merge!(:"#{field}_id" => object_or_type.id) if object_or_type.is_a?(::ActiveRecord::Base) && match.include?(:id)
        if match.include?(:type)
          type = case object_or_type
          when ::Class
            object_or_type.name
          when ::Symbol, ::String
            object_or_type.to_s.singularize.classify
          else 
            object_or_type.class.name
          end
          conditions.merge!(:"#{field}_type" => type)
        end
      end
    end
def polymorphic_conditions_for ( object_or_type , field , * match ) match = [ :id , :type ] if match . blank? returning ( { } ) do | conditions | conditions . merge! ( :" #{ field } _id " => object_or_type . id ) if object_or_type . is_a? ( :: ActiveRecord :: Base ) && match . include? ( :id ) if match . include? ( :type ) type = case object_or_type when :: Class object_or_type . name when :: Symbol , :: String object_or_type . to_s . singularize . classify else object_or_type . class . name end conditions . merge! ( :" #{ field } _type " => type ) end end end
Shortcut method for generating conditions hash for polymorphic belongs_to-associations.
Shortcut method for generating conditions hash for polymorphic belongs_to - associations .
# Note: {} is equivalent to Hash.new which takes a block, so we must do: ({}) or (Hash.new) # Object - or raise NameError as usual
object_or_type
<not_specific>
field
<not_specific>
match
<not_specific>