class ActiveRecord::DynamicMatchers::Instantiator - activerecord-deprecated_finders-1.0.4 Documentation

# class ActiveRecord::DynamicMatchers::Instantiator

### Public Class Methods

dispatch(klass, attribute_names, instantiator, args, block) click to toggle source

    # 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

### Public Instance Methods

body() click to toggle source

    # 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

deprecation_alternative() click to toggle source

    # File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 159
    def deprecation_alternative
      "Post.#{self.class.prefix}#{self.class.suffix}(name: 'foo')"
    end

instantiator() click to toggle source

    # File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 155
    def instantiator
      raise NotImplementedError
    end

signature() click to toggle source

    # File lib/active_record/deprecated_finders/dynamic_matchers.rb, line 144
    def signature
      "*args, &block"
    end