edge badge
Namespace
Methods
I
R
Instance Public methods
initializers()
# File railties/lib/rails/initializable.rb, line 66
def initializers
  @initializers ||= self.class.initializers_for(self)
end
run_initializers(group = :default, *args)
# File railties/lib/rails/initializable.rb, line 58
  def run_initializers(group = :default, *args)
    return if instance_variable_defined?(:@ran)
    initializers.tsort_each do |initializer|
      initializer.run(*args) if initializer.belongs_to?(group)
    end
    @ran = true
  end

  def initializers
    @initializers ||= self.class.initializers_for(self)
  end

  module ClassMethods
    def initializers
      @initializers ||= Collection.new
    end

    def initializers_chain
      initializers = Collection.new
      ancestors.reverse_each do |klass|
        next unless klass.respond_to?(:initializers)
        initializers = initializers + klass.initializers
      end
      initializers
    end

    def initializers_for(binding)
      Collection.new(initializers_chain.map { |i| i.bind(binding) })
    end

    def initializer(name, opts = {}, &blk)
      raise ArgumentError, "A block must be passed when defining an initializer" unless blk
      opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] }
      initializers << Initializer.new(name, nil, opts, &blk)
    end
  end
end