Class: Rails::Railtie::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/railtie/configuration.rb

Direct Known Subclasses

Engine::Configuration

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.


6
7
8
# File 'lib/rails/railtie/configuration.rb', line 6

def initialize
  @@options ||= {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object (private)


71
72
73
74
75
76
77
78
79
# File 'lib/rails/railtie/configuration.rb', line 71

def method_missing(name, *args, &blk)
  if name.to_s =~ /=$/
    @@options[$`.to_sym] = args.first
  elsif @@options.key?(name)
    @@options[name]
  else
    super
  end
end

Instance Method Details

#after_initialize(&block) ⇒ Object


53
54
55
# File 'lib/rails/railtie/configuration.rb', line 53

def after_initialize(&block)
  ActiveSupport.on_load(:after_initialize, :yield => true, &block)
end

#app_generatorsObject Also known as: generators

Holds generators configuration:

config.app_generators do |g|
  g.orm             :datamapper, :migration => true
  g.template_engine :haml
  g.test_framework  :rspec
end

If you want to disable color in console, do:

config.app_generators.colorize_logging = false

31
32
33
34
35
36
37
38
# File 'lib/rails/railtie/configuration.rb', line 31

def app_generators
  @@generators ||= Rails::Configuration::Generators.new
  if block_given?
    yield @@generators
  else
    @@generators
  end
end

#app_middlewareObject

This allows you to modify the application's middlewares from Engines.

All operations you run on the app_middleware will be replayed on the application once it is defined and the default_middlewares are created


15
16
17
# File 'lib/rails/railtie/configuration.rb', line 15

def app_middleware
  @@app_middleware ||= Rails::Configuration::MiddlewareStackProxy.new
end

#before_configuration(&block) ⇒ Object


41
42
43
# File 'lib/rails/railtie/configuration.rb', line 41

def before_configuration(&block)
  ActiveSupport.on_load(:before_configuration, :yield => true, &block)
end

#before_eager_load(&block) ⇒ Object


45
46
47
# File 'lib/rails/railtie/configuration.rb', line 45

def before_eager_load(&block)
  ActiveSupport.on_load(:before_eager_load, :yield => true, &block)
end

#before_initialize(&block) ⇒ Object


49
50
51
# File 'lib/rails/railtie/configuration.rb', line 49

def before_initialize(&block)
  ActiveSupport.on_load(:before_initialize, :yield => true, &block)
end

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)

65
66
67
# File 'lib/rails/railtie/configuration.rb', line 65

def respond_to?(name)
  super || @@options.key?(name.to_sym)
end

#to_prepare(&blk) ⇒ Object


61
62
63
# File 'lib/rails/railtie/configuration.rb', line 61

def to_prepare(&blk)
  to_prepare_blocks << blk if blk
end

#to_prepare_blocksObject


57
58
59
# File 'lib/rails/railtie/configuration.rb', line 57

def to_prepare_blocks
  @@to_prepare_blocks ||= []
end