Module: Rails::Initializable::ClassMethods
- Defined in:
- railties/lib/rails/initializable.rb
Instance Method Summary collapse
- #initializer(name, opts = {}, &blk) ⇒ Object
- #initializers ⇒ Object
- #initializers_chain ⇒ Object
- #initializers_for(binding) ⇒ Object
Instance Method Details
#initializer(name, opts = {}, &blk) ⇒ Object
131 132 133 134 135 136 137 |
# 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 |
#initializers ⇒ Object
114 115 116 |
# File 'railties/lib/rails/initializable.rb', line 114 def initializers @initializers ||= Collection.new end |
#initializers_chain ⇒ Object
118 119 120 121 122 123 124 125 |
# 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 |
#initializers_for(binding) ⇒ Object
127 128 129 |
# File 'railties/lib/rails/initializable.rb', line 127 def initializers_for(binding) Collection.new(initializers_chain.map { |i| i.bind(binding) }) end |