Changeset 1258 for trunk/lib

Show
Ignore:
Timestamp:
2008-11-18 23:02:23 (2 months ago)
Author:
gaspard
Message:

commit a0a697ffbe71e55929c5f7b92bc61a8a5f7de9df
Author: Gaspard Bucher <gaspard@teti.ch>

A lot of files moved around to ease extending zena by writing bricks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/base_additions.rb

    r1251 r1258  
    55end 
    66 
    7 load_patches_from_plugins 
     7class ActiveRecord::Base 
     8  def self.act_as_content 
     9    class_eval do 
     10      def preload_version(v) 
     11        @version = v 
     12      end 
     13   
     14      def version 
     15        @version ||= Version.find(self[:version_id]) 
     16      end 
     17    end 
     18  end 
     19end 
     20 
     21load_patches_from_bricks 
  • trunk/lib/core_ext/patcher.rb

    r1252 r1258  
    1 def foreach_plugin(&block) 
    2   plugins_folder = File.join(RAILS_ROOT, 'vendor', 'plugins') 
    3   Dir.foreach(plugins_folder) do |plugin
    4     next if plugin =~ /\A\./ 
    5     block.call(File.join(plugins_folder, plugin)) 
     1def foreach_brick(&block) 
     2  bricks_folder = File.join(RAILS_ROOT, 'bricks') 
     3  Dir.entries(bricks_folder).sort.each do |brick
     4    next if brick =~ /\A\./ 
     5    block.call(File.join(bricks_folder, brick)) 
    66  end 
    77end 
    88 
    9 def load_patches_from_plugin
     9def load_patches_from_brick
    1010  file_name = caller[0].split('/').last.split(':').first 
    11   foreach_plugin do |plugin_path| 
    12     patch_file = File.join(plugin_path, 'patch', file_name) 
     11  foreach_brick do |brick_path| 
     12    patch_file = File.join(brick_path, 'patch', file_name) 
    1313    if File.exist?(patch_file) 
    1414      load patch_file 
     
    1717end 
    1818 
    19 def load_models_from_plugins 
    20   foreach_plugin do |plugin_path| 
    21     models_path = File.join(plugin_path, 'models') 
     19def load_models_from_bricks 
     20  # make sure native models are loaded first 
     21  foreach_brick do |brick_path| 
     22    models_path = File.join(brick_path, 'models') 
    2223    next unless File.exist?(models_path) 
    2324    Dir.foreach(models_path) do |model_name| 
    2425      next if model_name =~ /\A\./ 
    25       load File.join(models_path, model_name) 
     26      eval model_name[/(\w+)\.rb/,1].capitalize.url_name 
    2627    end 
    2728  end 
    2829end 
     30 
     31def load_zafu_rules_from_bricks 
     32  foreach_brick do |brick_path| 
     33    zafu_path = File.join(brick_path, 'zafu') 
     34    next unless File.exist?(zafu_path) 
     35    Dir.foreach(zafu_path) do |rules_name| 
     36      next if rules_name =~ /\A\./ 
     37      load File.join(zafu_path, rules_name) 
     38    end 
     39  end 
     40end 
  • trunk/lib/parser/lib/rules/zena.rb

    r1255 r1258  
    33243324  end 
    33253325end 
     3326 
     3327load_zafu_rules_from_bricks 
  • trunk/lib/tasks/zena.rake

    r1250 r1258  
    926926      ENV['BRICK']    ||= 'zena' 
    927927      # migrate specific bricks only 
    928       mig_path = nil 
    929       Dir.foreach('db/migrate') do |file| 
    930         next if file =~ /^\./ 
    931         next unless File.stat("db/migrate/#{file}").directory? 
    932         if file =~ /^[0-9-_]*#{ENV["BRICK"]}/ 
    933           mig_path = "db/migrate/#{file}" 
    934           break 
    935         end 
    936       end 
    937       if mig_path 
    938         ActiveRecord::BricksMigrator.migrate(mig_path, ENV["BRICK"], ENV["VERSION"] ? ENV["VERSION"].to_i : nil) 
     928      if ENV['BRICK'] == 'zena' 
     929        # migrate 'db/migrate' 
     930        ActiveRecord::BricksMigrator.migrate('db/migrate', ENV["BRICK"], ENV["VERSION"] ? ENV["VERSION"].to_i : nil) 
    939931      else 
    940         puts "Brick migrations must exist in db/migrate/BRICK" 
     932        mig_path = "bricks/#{ENV['BRICK']}/migrate" 
     933        if File.exist?(mig_path) && File.directory?(mig_path) 
     934          ActiveRecord::BricksMigrator.migrate(mig_path, ENV["BRICK"], ENV["VERSION"] ? ENV["VERSION"].to_i : nil) 
     935        else 
     936          puts "Could not find migrations for brick '#{ENV['BRICK']}' ('#{mig_path}' not found)." 
     937        end 
    941938      end 
    942939    else 
    943940      # migrate all to latest 
    944       directories = [] 
    945       Dir.foreach('db/migrate') do |file| 
    946         next if file =~ /^\./ 
    947         next unless File.stat("db/migrate/#{file}").directory? 
    948         directories << file 
    949       end 
    950       directories.sort.each do |file| 
    951         brick_name = file.sub(/^[0-9-_]*/,'') 
    952         ActiveRecord::BricksMigrator.migrate("db/migrate/#{file}", brick_name, nil) 
    953       end 
    954       ActiveRecord::Migrator.migrate("db/migrate/", nil) 
     941      paths  = {'zena' => 'db/migrate'} 
     942      bricks = ['zena'] 
     943 
     944      foreach_brick do |brick_path| 
     945        brick_name = brick_path.split('/').last 
     946        migration_path = File.join(brick_path, 'migrate') 
     947        next unless File.exist?(migration_path) && File.directory?(migration_path) 
     948        paths[brick_name] = migration_path 
     949        bricks << brick_name 
     950      end 
     951      puts bricks.inspect 
     952      bricks.each do |brick_name| 
     953        ActiveRecord::BricksMigrator.migrate(paths[brick_name], brick_name, nil) 
     954      end 
     955      #ActiveRecord::Migrator.migrate("db/migrate/", nil) 
    955956    end 
    956957    Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby