lib/ez/rails_updater.rb in ez-1.9.3 vs lib/ez/rails_updater.rb in ez-1.9.4
- old
+ new
@@ -6,18 +6,22 @@
METHODS = %w(index show destroy new create edit update)
VIEWS = %w(index show destroy new create edit update)
def self.update!
+ return unless Rails.env.development?
+
EZ::DomainModeler.tables.each do |table|
create_controller(table) if EZ::Config.controllers?
create_view_folder(table) if EZ::Config.views?
create_routes(table) if EZ::Config.routes?
end
end
def self.create_routes(table)
+ return unless Rails.env.development?
+
filename = File.join(Rails.root, 'config', 'routes.rb')
line = " resources :#{table}"
routes = File.read(filename)
if !routes.index(line)
line = "#{line}\n"
@@ -26,10 +30,12 @@
File.open(filename, "wb") { |file| file.write(routes) }
end
end
def self.create_controller(controller)
+ return unless Rails.env.development?
+
filename = File.join(Rails.root, 'app', 'controllers', "#{controller}_controller.rb")
if !File.exist?(filename)
File.open(filename, "w:utf-8") do |file|
file.puts "class #{"#{controller}_controller".classify} < ApplicationController"
METHODS.each do |method|
@@ -43,9 +49,11 @@
end
end
end
def self.create_view_folder(folder)
+ return unless Rails.env.development?
+
full_path = File.join(Rails.root, 'app', 'views', folder)
FileUtils.mkdir_p(full_path)
VIEWS.each do |view|
File.open(File.join(full_path, "#{view}.html.erb"), "w:utf-8") do |file|
file.puts "<h1>This is a temporary page.</h1>"