Class: Appril::CLI::App::Install

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/appril-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, crudle_app: false) ⇒ Install

Returns a new instance of Install.



8
9
10
11
12
13
# File 'lib/appril-cli/app/install.rb', line 8

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

Instance Method Details

#add_namespace(dir, namespace) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/appril-cli/app/install.rb', line 25

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

#cleanup(dir) ⇒ Object



40
41
42
# File 'lib/appril-cli/app/install.rb', line 40

def cleanup dir
  Dir[dir / "**/.ignore"].each {|f| FileUtils.rm_f(f)}
end

#install(dir, working_dir_opted, crudle_app) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/appril-cli/app/install.rb', line 15

def install dir, working_dir_opted, crudle_app
  src = working_dir_opted ? APP_DIR.to_path + '/.' : APP_DIR
  FileUtils.cp_r(src, dir)
  if crudle_app
    FileUtils.rm_rf(dir / 'generators/api')
    FileUtils.cp_r(CRUDLE_DIR.to_path + '/.', dir)
  end
  cleanup(dir)
end