Class: Rdm::CLI::Init

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_dir:, test:, console:) ⇒ Init

Returns a new instance of Init.



11
12
13
14
15
# File 'lib/rdm/cli/init.rb', line 11

def initialize(current_dir:, test:, console:)
  @current_dir = current_dir
  @test        = test
  @console     = console
end

Instance Attribute Details

#consoleObject

Returns the value of attribute console.



10
11
12
# File 'lib/rdm/cli/init.rb', line 10

def console
  @console
end

#current_dirObject

Returns the value of attribute current_dir.



10
11
12
# File 'lib/rdm/cli/init.rb', line 10

def current_dir
  @current_dir
end

#testObject

Returns the value of attribute test.



10
11
12
# File 'lib/rdm/cli/init.rb', line 10

def test
  @test
end

Class Method Details

.run(opts = {}) ⇒ Object



5
6
7
# File 'lib/rdm/cli/init.rb', line 5

def run(opts = {})
  Rdm::CLI::Init.new(opts).run
end

Instance Method Details

#check_preconditions!Object



36
37
38
39
40
# File 'lib/rdm/cli/init.rb', line 36

def check_preconditions!
  return unless current_dir.empty?
  puts 'Current directory was not specified!'
  exit 1
end

#generateObject



28
29
30
31
32
33
34
# File 'lib/rdm/cli/init.rb', line 28

def generate
  Rdm::Gen::Init.generate(
    current_dir: current_dir,
    test:        test,
    console:     console
  )
end

#runObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/rdm/cli/init.rb', line 17

def run
  check_preconditions!
  begin
    generate
  rescue Errno::ENOENT => e
    puts "Error occurred. Possible reasons:\n #{current_dir} not found. Please run on empty directory \n#{e.inspect}"
  rescue Rdm::Errors::ProjectAlreadyInitialized
    puts 'Error. Project was already initialized.'
  end
end