# File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 128 def self.dispatch(klass, attribute_names, instantiator, args, block) if args.length == 1 && args.first.is_a?(Hash) attributes = args.first.stringify_keys conditions = attributes.slice(*attribute_names) rest = [attributes.except(*attribute_names)] else raise ArgumentError, "too few arguments" unless args.length >= attribute_names.length conditions = Hash[attribute_names.map.with_index { |n, i| [n, args[i]] }] rest = args.drop(attribute_names.length) end klass.where(conditions).first || klass.create_with(conditions).send(instantiator, *rest, &block) end
# File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 148 def body <<-CODE #{deprecation_warning} #{self.class}.dispatch(self, #{attribute_names.inspect}, #{instantiator.inspect}, args, block) CODE end
# File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 159 def deprecation_alternative "Post.#{self.class.prefix}#{self.class.suffix}(name: 'foo')" end
# File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 155 def instantiator raise NotImplementedError end
# File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 144 def signature "*args, &block" end