Class: Rails::Generator::Commands::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/content/content_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_factoryObject



5
6
7
8
9
# File 'lib/generators/content/content_generator.rb', line 5

def create_factory
  template = File.read(source_path('factories.rb'))
  source_to_update = ERB.new(template, nil, '-').result(binding)
  File.open('test/factories.rb', 'a') { |file| file.write("\n\n#{source_to_update}") }
end

#route_namespaced_resources(resource) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/generators/content/content_generator.rb', line 10

def route_namespaced_resources(resource)
  sentinel = "cms.namespace :admin, :path_prefix => '' do |admin|"
  logger.route "admin.resources #{resource}"
  unless options[:pretend]
    gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
      "#{match}\n\t\t\tadmin.resources :#{resource}, :collection => [:sort], :only => [:new, :create, :update, :edit, :destroy]"
    end
  end
end