Class: VisualMigrate::IndexController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- VisualMigrate::IndexController
- Defined in:
- app/controllers/visual_migrate/index_controller.rb
Instance Method Summary collapse
- #add_function ⇒ Object
- #command_line ⇒ Object
- #direct_edit ⇒ Object
- #direct_save ⇒ Object
- #edit_migration ⇒ Object
- #index ⇒ Object
- #run_command ⇒ Object
- #save_migration ⇒ Object
- #show_migrations ⇒ Object
- #show_select_columns ⇒ Object
- #show_tables ⇒ Object
Instance Method Details
#add_function ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 87 def add_function migration_class = MigrationDefs::MigrationClass.new(params[:class_name], params[:parent_name]) migration_class.parse_from_params params if !params[:new_func].nil? params[:new_func].each do |p_key, p_val| if !migration_class.methods.has_key?(p_key) migration_class.add_method(p_key) if p_val[:enable] == 'true' end migration_class.methods.each do |m_key, m_val| if !p_val[:new_table_name].blank? m_val.add_func(p_val[:type], p_val[:new_table_name]) if (p_key == m_key) && (p_val[:delete] != 'true') elsif !p_val[:table_name].blank? m_val.add_func(p_val[:type], p_val[:table_name]) if (p_key == m_key) && (p_val[:delete] != 'true') end end end end parsed_migration = RubyParser.new.parse(migration_class.get_str) @context = Ruby2Ruby.new.process(parsed_migration)#migration_class.get_str#params[:new_func].inspect# open(Rails.root.to_s + '/tmp/visual_migrate_tmp.rb', 'w') do |f| f.write(@context) end @tmp = true edit_migration end |
#command_line ⇒ Object
146 147 148 149 150 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 146 def command_line show_migrations render :command_line end |
#direct_edit ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 115 def direct_edit show_migrations if !params[:id].nil? migration_filename = Rails.root.to_s + '/db/migrate/' + params[:id] + '.rb' @migration_content = '' open(migration_filename, 'r') do |f| @migration_content = f.read end end begin @mi_lex = Ripper.lex(@migration_content) rescue end @edit_mode = 'direct_edit' render :direct_edit end |
#direct_save ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 135 def direct_save if !params[:migration].blank? migration_filename = Rails.root.to_s + '/db/migrate/' + params[:id] + '.rb' open(migration_filename, 'w') do |f| f.write params[:migration] end end direct_edit end |
#edit_migration ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 46 def edit_migration show_migrations if !params[:id].nil? || @tmp if !@tmp migration_filename = Rails.root.to_s + '/db/migrate/' + params[:id] + '.rb' else migration_filename = Rails.root.to_s + '/tmp/visual_migrate_tmp.rb' end @tmp = false open(migration_filename, 'r') do |f| @migration_content = f.read end @mi_lex = Ripper.lex(@migration_content) vm_filter = ClassFilter.new @migration_content vm_filter.parse @context = vm_filter.class.get_str @vm_ripper = vm_filter end render :edit_migration end |
#index ⇒ Object
42 43 44 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 42 def index edit_migration end |
#run_command ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 152 def run_command command = params[:command_line] if ((command =~ /^rake .*/) || (command =~ /^bundle .*/) || (command =~ /^rails .*/) || (command =~ /^git .*/)) && (command !~ /;/) #begin status, stdout, stderr = systemu command if stderr.blank? @run_result = stdout else @run_result = stdout + '<br /><font color="red">' + stderr + '</font>' end reset_session#db:migrate:down時にvalidationでエラーするので #rescue # @run_result = '<font color="red">failed</font>' #end else @run_result = '<font color="red">available commands are "rake", "bundle", "rails" and "git".</font>' end command_line end |
#save_migration ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 71 def save_migration migration_class = MigrationDefs::MigrationClass.new(params[:class_name], params[:parent_name]) migration_class.parse_from_params params parsed_migration = RubyParser.new.parse(migration_class.get_str) @context = Ruby2Ruby.new.process(parsed_migration)#migration_class.get_str#migration_class.get_str#params.inspect# #@tmp = true #open(Rails.root.to_s + '/tmp/visual_migrate_tmp.rb', 'w') do |f| open(Rails.root.to_s + '/db/migrate/' + params[:id] + '.rb', 'w') do |f| f.write(@context) end edit_migration end |
#show_migrations ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 20 def show_migrations @section_category = :migrations d = Pathname(Rails.root.to_s + '/db/migrate/') files = d.children @migration_files = [] files.each do |f| @migration_files << f if f.extname == '.rb' && f.basename.to_s !~ /\.visual_migrate\./ end end |
#show_select_columns ⇒ Object
36 37 38 39 40 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 36 def show_select_columns render :text => self.class.helpers.columns_select( '[methods][' + params[:method_name] + '][funcs][' + params[:func_name] + '][options][' + params[:row_num] + '][column]', params[:table_name], params[:column_select]) end |
#show_tables ⇒ Object
31 32 33 34 |
# File 'app/controllers/visual_migrate/index_controller.rb', line 31 def show_tables @section_category = :tables @tables = ActiveRecord::Base.connection.tables end |