- Timestamp:
- 2008-11-18 23:02:23 (2 months ago)
- Files:
-
- trunk/lib/base_additions.rb (modified) (1 diff)
- trunk/lib/core_ext/patcher.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (1 diff)
- trunk/lib/tasks/zena.rake (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/base_additions.rb
r1251 r1258 5 5 end 6 6 7 load_patches_from_plugins 7 class 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 19 end 20 21 load_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))1 def 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)) 6 6 end 7 7 end 8 8 9 def load_patches_from_ plugins9 def load_patches_from_bricks 10 10 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) 13 13 if File.exist?(patch_file) 14 14 load patch_file … … 17 17 end 18 18 19 def load_models_from_plugins 20 foreach_plugin do |plugin_path| 21 models_path = File.join(plugin_path, 'models') 19 def 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') 22 23 next unless File.exist?(models_path) 23 24 Dir.foreach(models_path) do |model_name| 24 25 next if model_name =~ /\A\./ 25 load File.join(models_path, model_name)26 eval model_name[/(\w+)\.rb/,1].capitalize.url_name 26 27 end 27 28 end 28 29 end 30 31 def 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 40 end trunk/lib/parser/lib/rules/zena.rb
r1255 r1258 3324 3324 end 3325 3325 end 3326 3327 load_zafu_rules_from_bricks trunk/lib/tasks/zena.rake
r1250 r1258 926 926 ENV['BRICK'] ||= 'zena' 927 927 # 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) 939 931 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 941 938 end 942 939 else 943 940 # 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) 955 956 end 956 957 Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
