Skip to Content Skip to Search

module Rails::Initializable::ClassMethods

Public instance methods

Source code GitHub
# File railties/lib/rails/initializable.rb, line 131
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.has?(opts[:before])
  initializers << Initializer.new(
    name, nil, before: opts[:before], after: opts[:after], group: opts[:group], &blk
  )
end
Source code GitHub
# File railties/lib/rails/initializable.rb, line 114
def initializers
  @initializers ||= Collection.new
end
Source code GitHub
# File railties/lib/rails/initializable.rb, line 118
def initializers_chain
  initializers = Collection.new
  ancestors.reverse_each do |klass|
    next unless klass.respond_to?(:initializers)
    initializers = initializers + klass.initializers
  end
  initializers
end
Source code GitHub
# File railties/lib/rails/initializable.rb, line 127
def initializers_for(binding)
  Collection.new(initializers_chain.map { |i| i.bind(binding) })
end

Definition files