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)



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

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



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

def after_initialize(&block)
  ActiveSupport.on_load(:after_initialize, :yield => true, &block)
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



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

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

#before_eager_load(&block) ⇒ Object



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

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

#before_initialize(&block) ⇒ Object



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

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

#generatorsObject

Holds generators configuration:

config.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.generators.colorize_logging = false


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

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

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_prepare(&blk) ⇒ Object



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

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

#to_prepare_blocksObject



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

def to_prepare_blocks
  @@to_prepare_blocks ||= []
end