Changeset 853

Show
Ignore:
Timestamp:
11/05/07 22:33:04 (1 year ago)
Author:
iv..@gweezlebur.com
Message:

Added use_orm and use_test helpers to manage GENERATOR_SCOPE (and dependencies for ORMs)

Files:

Legend:

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

    r831 r853  
    1 puts "Loading dependencies..." 
    2  
    31# Make the app's "gems" directory a place where gems are loaded from 
    42Gem.clear_paths 
     
    86$LOAD_PATH.unshift(MERB_ROOT / "lib") 
    97 
    10 ### Uncomment for Sequel ORM 
    11 # dependency "merb_sequel" 
     8### Merb doesn't come with database support by default.  You need 
     9### an ORM plugin.  Install one, and uncomment one of the following lines, 
     10### if you need a database. 
     11 
     12### Uncomment for DataMapper ORM 
     13# use_orm "merb_data_mapper" 
    1214 
    1315### Uncomment for ActiveRecord ORM 
    14 # dependency "merb_active_record" 
     16# use_orm "merb_active_record" 
    1517 
    16 ### Uncomment for DataMapper ORM 
    17 # dependency "merb_data_mapper" 
     18### Uncomment for Sequel ORM 
     19# use_orm "merb_sequel" 
     20 
     21 
     22### This defines which test framework the generators will use 
     23### rspec is turned on by default 
     24# use_test :test_unit 
     25use_test :rspec 
    1826 
    1927### Add your other dependencies here 
  • trunk/app_generators/merb/templates/config/merb_init.rb

    r824 r853  
    1515# Load environment-specific configuration 
    1616require File.join(MERB_ROOT, 'config', 'environments', MERB_ENV) 
    17  
    18 # Set the scope for generators used in this app 
    19 # The first generator matched will be used, where the generators are 
    20 # searched in the following order. 
    21 # If you are using an ORM plugin, that should come first, 
    22 # then merb, then the test framework you want. 
    23 # 
    24 # Example 
    25 # 
    26 # To use data_mapper, merb and rspec 
    27 # [:data_mapper, :merb, :rspec] 
    28 # 
    29 # To use active_record, merb and test_unit 
    30 # [:active_record, :merb, :test_unit] 
    31 # 
    32 # To use plain merb without an ORM and rspec 
    33 # [:merb, :rspec] 
    34 Merb::GENERATOR_SCOPE = [:merb, :rspec] 
  • trunk/lib/merb.rb

    r804 r853  
    5959    end   
    6060  end 
     61   
     62  # Set up default generator scope 
     63  GENERATOR_SCOPE = [:merb_default, :merb, :rspec] 
    6164end 
    6265 
  • trunk/lib/merb/core_ext/kernel.rb

    r784 r853  
    3434  def dependency(gem, *ver) 
    3535    Gem.activate(gem, true, *ver) 
     36  end 
     37   
     38  def use_orm(orm) 
     39    orm = orm.to_s 
     40    orm = "merb_#{orm}" unless orm.match(/^merb_/) 
     41    Merb::GENERATOR_SCOPE.delete(:merb_default) 
     42    Merb::GENERATOR_SCOPE.unshift(orm.to_sym) unless 
     43      Merb::GENERATOR_SCOPE.include?(orm.to_sym) 
     44    Kernel.dependency(orm) 
     45  end 
     46   
     47  def use_test(test_framework) 
     48    test_framework = test_framework.to_sym 
     49    raise "use_test only supports :rspec and :test_unit currently" unless 
     50      [:rspec, :test_unit].include?(test_framework) 
     51    Merb::GENERATOR_SCOPE.delete(:rspec) 
     52    Merb::GENERATOR_SCOPE.delete(:test_unit) 
     53    Merb::GENERATOR_SCOPE.push(test_framework) 
    3654  end 
    3755