7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/generators/jimothy/install_generator.rb', line 7
def install_jimothy
if !Dir[Rails.root + 'app/models/*.rb'].map { |path| path.split('/')[-1] }.include? 'user.rb'
%x(rails g scaffold user name email image)
%x(rails db:migrate)
gsub_file 'app/views/users/_user.html.erb',/<%= user.image %>/,'<%= image_tag user.image %>'
gsub_file 'db/seeds.rb',/# This file should contain all the record creation needed to seed the database with its default values.\n# The data can then be loaded with the bin\/rails db:seed command \(or created alongside the database with db:setup\).\n#\n# Examples:\n#\n# movies = Movie.create\(\[\{ name: \"Star Wars\" \}, \{ name: \"Lord of the Rings\" \}\]\)\n# Character.create\(name: \"Luke\", movie: movies.first\)\n/,'.'
seeds_file = File.read('db/seeds.rb')
if seeds_file == '.' gsub_file 'db/seeds.rb',/./,"require \"jimothy\"\nJimothy::seed_users"
end
%x(rails db:seed)
else
puts "Error: user model already exists. Skipping jimothy install."
end
end
|