Class: Lolita::Generators::UninstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Lolita::Generators::UninstallGenerator
- Defined in:
- lib/generators/lolita/uninstall_generator.rb
Constant Summary collapse
- ROUTE_NAME =
"lolita_for"
- INCLUDE_MODULE =
"Lolita::Configuration"
- MODEL_METHOD =
"lolita"
Instance Method Summary collapse
-
#clear_models ⇒ Object
Remove configuration include line and lolita block or single lolita method call.
-
#clear_routes ⇒ Object
Remove all not-commented lines that begins with lolita_for.
-
#remove_initializer ⇒ Object
Remove lolita initializer file.
-
#remove_tinymce ⇒ Object
Remove tinymce.yml config file.
Instance Method Details
#clear_models ⇒ Object
Remove configuration include line and lolita block or single lolita method call. Block will be removed correctly if it starts with do and ends with end.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/generators/lolita/uninstall_generator.rb', line 30 def clear_models Dir[Rails.root.join("app","models","*.rb")].each do |file_name| matched = false gsub_file file_name, /^\s*include\s+#{INCLUDE_MODULE}.*/ do |match| matched = true match.clear match end if matched new_lines = [] File.open(file_name,"r") do |file| do_count = nil file.each_line do |line| if do_count.nil? if line.match(/^(\s*)lolita\s+(do)?/) if $2 == "do" do_count = 1 else do_count = 0 end else new_lines << line end elsif do_count > 0 if line.match(/(^|\s+)do(\s+|$)/) do_count +=1 elsif line.match(/(^|\s+)end(\s+|$)/) do_count -=1 end else new_lines << line end end end File.open(file_name,"w") do |file| new_lines.each do |line| file.puts(line) end end end end end |
#clear_routes ⇒ Object
Remove all not-commented lines that begins with lolita_for
21 22 23 24 25 26 |
# File 'lib/generators/lolita/uninstall_generator.rb', line 21 def clear_routes gsub_file Rails.root.join("config","routes.rb"), /^\s*#{ROUTE_NAME}.*/ do |match| match.clear match end end |
#remove_initializer ⇒ Object
Remove lolita initializer file
11 12 13 |
# File 'lib/generators/lolita/uninstall_generator.rb', line 11 def remove_initializer remove_file "config/initializers/lolita.rb" end |
#remove_tinymce ⇒ Object
Remove tinymce.yml config file
16 17 18 |
# File 'lib/generators/lolita/uninstall_generator.rb', line 16 def remove_tinymce remove_file "config/tinymce.yml" end |