Class: Sinatra::CLI::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/sinatra/cli/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



10
11
12
# File 'lib/sinatra/cli/generator.rb', line 10

def self.source_root
  File.join(File.dirname(__FILE__), "../../../", "templates")
end

Instance Method Details

#bundle_installObject



84
85
86
# File 'lib/sinatra/cli/generator.rb', line 84

def bundle_install
  system "cd #{app_name} && bundle install && cd ../"
end

#create_app_fileObject



41
42
43
# File 'lib/sinatra/cli/generator.rb', line 41

def create_app_file
  copy_file "app.rb", "#{app_name}/app.rb"
end

#create_assetsObject



31
32
33
34
35
# File 'lib/sinatra/cli/generator.rb', line 31

def create_assets
  create_file "#{app_name}/public/javascripts/app.js"
  create_file "#{app_name}/public/stylesheets/app.css"
  keep_file "#{app_name}/public/images/"
end

#create_database_configObject



23
24
25
# File 'lib/sinatra/cli/generator.rb', line 23

def create_database_config
  template "config/database.yml.erb", "#{app_name}/config/database.yml"
end

#create_gemfileObject



45
46
47
# File 'lib/sinatra/cli/generator.rb', line 45

def create_gemfile
  copy_file "Gemfile", "#{app_name}/Gemfile"
end

#create_gitignoreObject



37
38
39
# File 'lib/sinatra/cli/generator.rb', line 37

def create_gitignore
  copy_file ".gitignore", "#{app_name}/.gitignore"
end

#create_models_dirObject



14
15
16
# File 'lib/sinatra/cli/generator.rb', line 14

def create_models_dir
  keep_file "#{app_name}/app/models"
end

#create_rakefileObject



49
50
51
# File 'lib/sinatra/cli/generator.rb', line 49

def create_rakefile
  copy_file "Rakefile", "#{app_name}/Rakefile"
end

#create_readmeObject



53
54
55
# File 'lib/sinatra/cli/generator.rb', line 53

def create_readme
  template "README.md.erb", "#{app_name}/README.md"
end

#create_seeds_fileObject



27
28
29
# File 'lib/sinatra/cli/generator.rb', line 27

def create_seeds_file
  copy_file "db/seeds.rb", "#{app_name}/db/seeds.rb"
end

#create_views_dirObject



18
19
20
21
# File 'lib/sinatra/cli/generator.rb', line 18

def create_views_dir
  template "app/views/index.erb", "#{app_name}/app/views/index.erb"
  template "app/views/layout.erb", "#{app_name}/app/views/layout.erb"
end

#setup_capybaraObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sinatra/cli/generator.rb', line 68

def setup_capybara
  insert_into_file(
    "#{app_name}/Gemfile",
    "gem 'capybara'",
    after: "group :test, :development do"
  )

  insert_into_file(
    "#{app_name}/spec/spec_helper.rb",
    "require 'capybara/rspec'",
    after: "require 'rspec'"
  )

  append_to_file "#{app_name}/spec/spec_helper.rb", "\n\nCapybara.app = Sinatra::Application"
end

#setup_rspecObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/sinatra/cli/generator.rb', line 57

def setup_rspec
  insert_into_file(
    "#{app_name}/Gemfile",
    "gem 'rspec'",
    after: "group :test, :development do"
  )

  copy_file ".rspec", "#{app_name}/.rspec"
  copy_file "spec/spec_helper.rb", "#{app_name}/spec/spec_helper.rb"
end