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
32
33
34
35
36
37
38
39
40
|
# File 'lib/generators/avo/setup_generator.rb', line 7
def setup
if yes?("Would you like to generate a layout?")
generate("avo:layout")
end
if yes?("Would you like to use simple-form for form generation?")
gem("simple_form")
end
if yes?("Would you like to use Devise for authentication?")
gem("devise", ">=1.2")
generate("devise:install")
model_name = ask("What would you like the user model to be called? [user]")
model_name = "user" if model_name.blank?
generate("devise", model_name)
generate("devise:views")
if yes?("Would you like to use CanCan for authorization?")
gem("cancan")
copy_file "ability.rb", "models/ability.rb"
@single=model_name
inject_into_class "app/models/"+@single.underscore+".rb", model_name.camelcase, "has_and_belongs_to_many :roles\n"
@plural=model_name.pluralize
template "role.rb", "app/models/role.rb"
@migname=@plural+"_roles" if (@plural.casecmp "roles")<0
@migname="roles_"+@plural if (@plural.casecmp "roles")>=0
migration_template 'create_roles_migration.rb', "db/migrate/create_roles.rb"
end
end
end
|