Class: Sombrero::CLI::App::Install

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/sombrero/cli/app/install.rb

Instance Method Summary collapse

Methods included from Helpers

#create_dirname_for, #display_error, #expanded_path, #extract_namespace, #fatal_error!, #make_executable, #working_dir_opted?

Constructor Details

#initialize(dir, namespace: nil, working_dir_opted: false) ⇒ Install

Returns a new instance of Install.



7
8
9
10
11
12
# File 'lib/sombrero/cli/app/install.rb', line 7

def initialize dir, namespace: nil, working_dir_opted: false
  install(dir, working_dir_opted)
  make_executable(dir / 'core/generate_webpack_setup.rb', dir / 'core/generate_controllers_map.rb')
  add_namespace(dir, namespace) if namespace
  puts "Done. All files installed into #{dir}"
end

Instance Method Details

#add_namespace(dir, namespace) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sombrero/cli/app/install.rb', line 19

def add_namespace dir, namespace
  %w[
    base/base_controller.rb
    base/rtcp_controller.rb
    config/config.rb
  ].each do |file|
    code = File.read(dir / file)
    File.open dir / file, 'w' do |f|
      f.puts "module #{namespace}"
      code.split("\n").each {|l| f.puts "  #{l}"}
      f.puts "end"
    end
  end
end

#install(dir, working_dir_opted) ⇒ Object



14
15
16
17
# File 'lib/sombrero/cli/app/install.rb', line 14

def install dir, working_dir_opted
  src = working_dir_opted ? BASE_DIR.to_path + '/.' : BASE_DIR
  FileUtils.cp_r(src, dir)
end