Sha256: 89ca811f5369b6a9fe6d4b4a17e5b1644efa1aa5e6d913015dd66936766296c1
Contents?: true
Size: 1.85 KB
Versions: 27
Compression:
Stored size: 1.85 KB
Contents
# frozen_string_literal: true # encoding: utf-8 module Mongoid module Errors # This error is raised when trying to create an association that conflicts with # an already defined method. # # @since 6.0.0 class InvalidRelation < MongoidError # Create the new error. # # @example Create the error. # InvalidRelation.new(person, :crazy_relation_name) # # @param [ Class ] klass The document class. # @param [ Symbol ] name The method name. def initialize(klass, name) super( compose_message( "invalid_relation", { name: name, origin: origin(klass, name), file: location(klass, name)[0], line: location(klass, name)[1] } ) ) end private # Get the queryable of the method. # # @example Get the originating class or module. # error.queryable(Person, :crazy_method_name) # # @param [ Class ] klass The document class. # @param [ Symbol ] name The method name. # # @return [ Class, Module ] The originating class or module. # # @since 6.0.0 def origin(klass, name) klass.instance_method(name).owner end # Get the location of the association definition. # # @example Get the location of the method on the filesystem. # error.location(Person, :crazy_method_name) # # @param [ Class ] klass The document class. # @param [ Symbol ] name The method name. # # @return [ Array<String, Integer> ] The location of the method. # # @since 6.0.0 def location(klass, name) @location ||= (klass.instance_method(name).source_location || [ "Unknown", 0 ]) end end end end
Version data entries
27 entries across 27 versions & 2 rubygems