lib/search_rails.rb in search_rails-1.0.4 vs lib/search_rails.rb in search_rails-1.0.5

- old
+ new

@@ -14,10 +14,13 @@ File.new "search_module.rb", "w" puts "Created ".green.bold + '/app/search/search_module.rb'.bold Dir.chdir(root + '/app/controllers') File.new "searches_controller.rb", "w" puts "Created ".green.bold + '/app/controllers/searches_controller.rb'.bold + Dir.chdir(root + '/app/models') + File.new "search.rb", "w" + puts 'Created '.green.bold + 'app/models/search.rb'.bold Dir.chdir(root + '/db') if File.exists?('/migrate') else FileUtils::mkdir_p "migrate" puts "Created ".green.bold + '/db/migrate'.bold @@ -158,10 +161,39 @@ end puts "Updated ".green.bold + '/app/controllers/application_controller.rb'.bold Dir.chdir(root) end + def write_search_model + require "fileutils" + root = Dir.pwd + Dir.chdir(root + '/app/models') + File.open("search.rb", "w") do |line| + line.puts 'class Search < ActiveRecord::Base' + line.puts 'end' + end + Dir.chdir(root) + end + + def update_routes + require "fileutils" + root = Dir.pwd + Dir.chdir(root + '/config') + first_line = IO.readlines("routes.rb")[0] + other_lines = IO.readlines("routes.rb")[1..1000000000] + File.open('routes.rb', 'w') do |line| + line.puts first_line + line.puts 'resources :searches do' + line.puts ' member do' + line.puts " get 'clear'" + line.puts ' end' + line.puts 'end' + line.puts other_lines + end + Dir.chdir(root) + end + def run require 'colorize' puts "Syntax: 'install OBJECT ATTRIBUTE:TYPE'".bold.on_red command = gets.chomp @@ -174,10 +206,12 @@ end SearchInstall.new.create_files SearchInstall.new.write_search_controller SearchInstall.new.write_application_controller + SearchInstall.new.write_search_model SearchInstall.new.write_migration + SearchInstall.new.update_routes SearchInstall.new.write_search_module(object, attributes) puts 'Done'.bold puts '' rescue puts ''