Class: Scruber::CLI::ProjectGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



14
15
16
# File 'lib/scruber/cli/project_generator.rb', line 14

def self.source_root
  File.dirname(__FILE__) + '/templates'
end

Instance Method Details

#create_directoriesObject

Raises:

  • (::Thor::Error)


18
19
20
21
22
23
24
# File 'lib/scruber/cli/project_generator.rb', line 18

def create_directories
  raise ::Thor::Error, "ERROR: #{path} already exists." if File.exist?(path)
  say "Creating scruber project at #{path}"
  FileUtils.mkdir_p(path)
  FileUtils.mkdir_p(path+'/lib')
  FileUtils.mkdir_p(path+'/log')
end

#create_filesObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/scruber/cli/project_generator.rb', line 26

def create_files
  template 'Gemfile.tt', path+'/Gemfile'
  template 'gitignore.tt', path+'/.gitignore'
  template 'bin/scruber.tt', path+'/bin/scruber'
  chmod path+'/bin/scruber', '+x'
  template 'application.tt', path+'/config/application.rb'
  template 'boot.tt', path+'/config/boot.rb'
  template 'initializers/proxies.tt', path+'/config/initializers/proxies.rb'
  template 'initializers/user_agents.tt', path+'/config/initializers/user_agents.rb'
  template 'scrapers/sample.tt', path+'/scrapers/sample.rb'
end

#init_projectObject



38
39
40
41
42
# File 'lib/scruber/cli/project_generator.rb', line 38

def init_project
  inside path do
    run "bundle"
  end
end


44
45
46
# File 'lib/scruber/cli/project_generator.rb', line 44

def print_instructions
  say "Run `scruber start sample` to run sample scraper"
end