Class: Ree::Gen::Init

Inherits:
Object show all
Defined in:
lib/ree/gen/init.rb

Constant Summary collapse

TEMPLATE_NAME =
'init'
INIT_PATH =
'./'
LOCAL_TEMPLATES_PATH =
'.ree/templates'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path, test, console, stdout) ⇒ Init

Returns a new instance of Init.



19
20
21
22
23
24
25
# File 'lib/ree/gen/init.rb', line 19

def initialize(project_path, test, console, stdout)
  @project_path      = project_path
  @test              = test
  @console           = console
  @template_detector = Ree::TemplateDetector.new(project_path)
  @stdout            = stdout
end

Class Method Details

.generate(project_path:, test: 'rspec', console: 'irb', stdout: STDOUT) ⇒ Object



14
15
16
# File 'lib/ree/gen/init.rb', line 14

def generate(project_path:, test: 'rspec', console: 'irb', stdout: STDOUT)
  Ree::Gen::Init.new(project_path, test, console, stdout).generate
end

Instance Method Details

#generateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ree/gen/init.rb', line 27

def generate
  if @project_path.nil? || @project_path.empty?
    raise Ree::Error.new("Project folder not specified. Type path to ree project, ex: 'ree init .'")
  end

  if !Dir.exist?(@project_path)
    raise Ree::Error.new("#{@project_path} doesn't exist. Initialize new ree project with existing directory")
  end

  if File.exist?(File.join(@project_path, Ree::PACKAGES_SCHEMA_FILE))
    raise Ree::Error.new("#{@project_path} has already #{Ree::PACKAGES_SCHEMA_FILE}")
  end

  generated_files = Ree::TemplateHandler.generate(
    template_name: TEMPLATE_NAME,
    project_path: @project_path,
    local_path: INIT_PATH,
    stdout: @stdout
  )

  FileUtils.mkdir_p(local_templates_path)

  FileUtils.cp_r(
    @template_detector.gem_template_folder('package'),
    File.dirname(@template_detector.project_template_folder('package'))
  )

  generated_files
end