Browse files

[^] new_configuration generator improved

  • Loading branch information...
1 parent 3317292 commit de68b640cda49ee66c252ccebff4f17e9bf8c118 @romanvbabenko romanvbabenko committed May 16, 2011
Showing with 25 additions and 19 deletions.
  1. +9 −9 lib/application_checker.rb
  2. +16 −10 lib/new_configuration_generator.rb
View
18 lib/application_checker.rb
@@ -50,15 +50,15 @@ def check_ar_methods
)
end
end
-
+
def check_validation_on_methods
files = []
-
+
["validate_on_create", "validate_on_update"].each do |v|
lines = grep_for(v, "app/models/")
files += extract_filenames(lines) || []
end
-
+
unless files.empty?
alert(
"Updated syntax for validate_on_* methods",
@@ -68,15 +68,15 @@ def check_validation_on_methods
)
end
end
-
+
def check_before_validation_on_methods
files = []
-
+
%w(before_validation_on_create before_validation_on_update).each do |v|
lines = grep_for(v, "app/models/")
files += extract_filenames(lines) || []
end
-
+
unless files.empty?
alert(
"Updated syntax for before_validation_on_* methods",
@@ -223,7 +223,7 @@ def check_generators
unless generators.empty?
files = generators.reject do |g|
- grep_for("def manifest", g).empty?
+ grep_for("def manifest", g).empty?
end.compact
unless files.empty?
@@ -267,7 +267,7 @@ def check_old_helpers
lines += grep_for("<% .*form_tag.* do.*%>", "app/views/**/*")
lines += grep_for("<% .*fields_for.* do.*%>", "app/views/**/*")
lines += grep_for("<% .*field_set_tag.* do.*%>", "app/views/**/*")
-
+
files = extract_filenames(lines)
if !files.blank?
@@ -355,7 +355,7 @@ def grep_for_with_perl_regex(text, where = "./", double_quote = false)
def grep_for(text, where = "./", double_quote = false, perl_regex = false)
# If they're on Windows, they probably don't have grep.
@probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
-
+
# protect against double root paths in Rails 3
where.gsub!(Regexp.new(base_path),'')
View
26 lib/new_configuration_generator.rb
@@ -8,44 +8,50 @@ def generate_new_configurations
raise FileNotFoundError, "Can't find environment.rb [config/environment.rb]!"
end
end
-
+
def has_environment?
File.exists?("config/environment.rb")
end
-
+
def environment_code
File.open("config/environment.rb").read
end
-
+
def generate_new_application_rb
environment_file = environment_code
-
+
initializer_code = ""
if matches = environment_file.match(/Rails\:\:Initializer\.run do \|config\|\n(.*)\nend/m)
initializer_code = matches[1]
else
raise "There doesn't seem to be a real environment.rb in your app. Are you sure config/environment.rb has the right contents?"
end
-
+
frame = "# Put this in config/application.rb
require File.expand_path('../boot', __FILE__)
+require 'rails/all'
+
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
module #{app_name.classify}
class Application < Rails::Application
+ config.autoload_paths += [config.root.join('lib')]
+ config.encoding = 'utf-8'
%s
end
end"
-
- frame % [indent(initializer_code)]
+
+ frame % [indent(initializer_code)]
end
-
+
def indent(text)
text.split("\n").map {|l| " #{l}"}.join("\n")
end
-
+
def app_name
File.basename(Dir.pwd)
end
end
end
-end
+end

0 comments on commit de68b64

Please sign in to comment.