Changeset 6145

Show
Ignore:
Timestamp:
11/28/06 13:42:34
Author:
jan
Message:

adding filter feature to hibernatexport

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/example/Rakefile

    r6138 r6145  
    102102  t.entities_yml = ENTITIES_YML 
    103103end 
     104 
     105Jerbil::Hibernate::ExportSchemaTask.new(:export_schema_filtered) do |t| 
     106  t.schemafile = DB_SCHEMA 
     107  t.entities_yml = ENTITIES_YML 
     108  t.filter { |classname| classname =~ /^merbil\./ } 
     109end 
     110 
     111 
  • trunk/lib/jerbil/hibernate_task.rb

    r6139 r6145  
    4545        @dependencies = [] 
    4646        @package = nil 
     47        @classfilter = nil 
    4748        @schemafile = "schema.sql" 
    4849        @entities_yml = "entities.yml" 
     
    6061          raise 'no annotated entities found!' if entities.empty? 
    6162           
    62           #puts "found #{entities.size} entities" 
    63            
     63          #puts "found #{entities.size} entities"     
     64          entities = entities.dup.select { |e| @classfilter.call(e) } if @classfilter          
    6465          entity_classes = entities.map {|klass| Rjb::import(klass)} 
    6566           
     
    8384        file schemafile => name 
    8485        task name => entities_yml 
    85       end   
     86      end 
     87       
     88      # Filters all entities. Useful to only export schema for a subset of classes. 
     89      # ==Example 
     90      # Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t| 
     91      #    t.filter { |classname| classname =~ /^foo/ }     
     92      #  end 
     93      def filter(*args, &block) 
     94          @classfilter = block 
     95      end 
    8696    end 
    8797   
  • trunk/test/test_build.rb

    r6060 r6145  
    7575      assert ok 
    7676      assert File.exists?(DB_SCHEMA) 
     77      #make sure file is not empty 
     78      assert File.size(DB_SCHEMA) >= 200 
    7779    end 
    7880  end 
     81   
     82  def test_export_schema_filtered 
     83    run_rake_clean(:export_schema_filtered) do |ok,res| 
     84      assert ok 
     85      assert File.exists?(DB_SCHEMA) 
     86      #make sure file is empty 
     87      assert File.size(DB_SCHEMA) <= 150 
     88    end 
     89  end 
     90   
    7991   
    8092  def test_run_no_fork