Class: Rdm::Gen::Init

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_path, test, console) ⇒ Init

Returns a new instance of Init.



17
18
19
20
21
22
# File 'lib/rdm/gen/init.rb', line 17

def initialize(current_path, test, console)
  @current_path      = current_path
  @test              = test
  @console           = console
  @template_detector = Rdm::Templates::TemplateDetector.new(current_path)
end

Class Method Details

.generate(current_path:, test: 'rspec', console: 'irb') ⇒ Object



12
13
14
# File 'lib/rdm/gen/init.rb', line 12

def generate(current_path:, test: 'rspec', console: 'irb')
  Rdm::Gen::Init.new(current_path, test, console).generate
end

Instance Method Details

#generateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rdm/gen/init.rb', line 24

def generate
  if @current_path.nil? || @current_path.empty?
    raise Rdm::Errors::InvalidParams, "Error. Project folder not specified. Type path to rdm project, ex: 'rdm init .'" 
  end
  raise Rdm::Errors::InvalidProjectDir, @current_path unless Dir.exist?(@current_path)

  if File.exist?(File.join(@current_path, Rdm::SOURCE_FILENAME))
    raise Rdm::Errors::ProjectAlreadyInitialized, "#{@current_path} has already #{Rdm::SOURCE_FILENAME}"
  end

  FileUtils.mkdir_p(local_templates_path)
  FileUtils.cp_r(
    @template_detector.gem_template_folder('package'),
    @template_detector.project_template_folder('package')
  )
  
  Rdm::Handlers::TemplateHandler.generate(
    template_name:      TEMPLATE_NAME,
    current_path:       @current_path,
    local_path:         INIT_PATH,
    ignore_source_file: true
  )
end