Changeset 1044

Show
Ignore:
Timestamp:
11/24/07 14:47:17 (1 year ago)
Author:
e.@brainspl.at
Message:

add environment specific merb.yml files that can overide whats in the global merb.yml. closes #319

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app_generators/merb/templates/config/merb.yml

    r1039 r1044  
    6767# set this to the layout template (or :none) that you want to use by default 
    6868#:exception_layout: :none 
    69    
     69 
     70# You can override settings for specific environments by creating a yaml 
     71# file for that environment in config/environments.  For example, to 
     72# change the configuration only for development create 
     73# config/environments/development.yml 
  • trunk/lib/merb/core_ext/kernel.rb

    r856 r1044  
    11module Kernel 
    2   # Example: 
    3   #   acquire 'foo/bar/*' 
    4   # requires all files inside foo/bar - recursive 
    5   # can take multiple parameters 
    6   def acquire(*files) 
    7     files.each do |file| 
    8       require file if %w(rb so).any?{|f| File.file?("#{file}.#{f}")} 
    9       $:.each do |path| 
    10         Dir[File.join(path, file, '*.rb')].each do |file| 
    11           require file 
    12         end 
    13       end 
    14     end 
    15   end 
    162   
    173  # does a basic require, and prints the message passed as an optional 
     
    126112  # Extracts an options hash if it is the last item in the args array 
    127113  def extract_options_from_args!(args) 
    128     args.pop if args.last.is_a?( Hash ) 
     114    args.pop if Hash === args.last 
    129115  end 
    130116   
  • trunk/lib/merb/server.rb

    r1039 r1044  
    2929          $LOAD_PATH.unshift( "#{defaults[:merb_root]}/framework" ) 
    3030        end 
    31         merb_yml = "#{defaults[:merb_root]}/config/merb.yml"       
    32         if File.exists?(merb_yml) 
     31        global_merb_yml = "#{defaults[:merb_root]}/config/merb.yml" 
     32        apply_configuration_from_file defaults, global_merb_yml 
     33      end 
     34 
     35      def apply_configuration_from_file(configuration, file) 
     36        if File.exists?(file) 
    3337          require 'merb/erubis_ext' 
    34           defaults.merge(Erubis.load_yaml_file(merb_yml)) 
     38          configuration.merge(Erubis.load_yaml_file(file)) 
    3539        else 
    36           defaults 
     40          configuration 
    3741        end 
    3842      end 
     
    4448    class << self 
    4549       
    46       def merb_config 
     50      def merb_config(argv = ARGV) 
    4751        options = Merb::Config.setup 
    4852       
     
    155159 
    156160        # Special case of looking for help 
    157         if ARGV == ["-h"] 
     161        if argv == ["-h"] 
    158162          puts opts   
    159163          exit 
    160164        end 
    161         opts.parse!(@@merb_raw_opts
     165        opts.parse!(argv
    162166        # merb <argument> is same as merb -g <argument> 
    163         if ARGV.size == 1 
    164           options[:generate] = File.expand_path(ARGV.last) 
     167        if argv.size == 1 
     168          options[:generate] = File.expand_path(argv.last) 
    165169        end 
    166170       
     
    193197          options[:environment] = 'development' 
    194198        end 
     199         
     200         
     201        environment_merb_yml = "#{options[:merb_root]}/config/environments/#{options[:environment]}.yml"         
     202        options = Merb::Config.apply_configuration_from_file options, environment_merb_yml 
    195203 
    196204        @@merb_opts = options