Class: Larva::DaemonCreator

Inherits:
Object show all
Defined in:
lib/larva/daemon_creator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pwd, daemon_name) ⇒ DaemonCreator

Returns a new instance of DaemonCreator.



10
11
12
13
14
# File 'lib/larva/daemon_creator.rb', line 10

def initialize(pwd, daemon_name)
  @template_dir = File.expand_path('../../../template', __FILE__)
  @daemon_name = daemon_name
  @daemon_dir = "#{pwd}/#{daemon_name}"
end

Instance Attribute Details

#daemon_dirObject (readonly)

Returns the value of attribute daemon_dir.



9
10
11
# File 'lib/larva/daemon_creator.rb', line 9

def daemon_dir
  @daemon_dir
end

#daemon_nameObject (readonly)

Returns the value of attribute daemon_name.



9
10
11
# File 'lib/larva/daemon_creator.rb', line 9

def daemon_name
  @daemon_name
end

#template_dirObject (readonly)

Returns the value of attribute template_dir.



9
10
11
# File 'lib/larva/daemon_creator.rb', line 9

def template_dir
  @template_dir
end

Class Method Details

.create(*args) ⇒ Object



5
6
7
# File 'lib/larva/daemon_creator.rb', line 5

def self.create(*args)
  new(*args).create
end

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/larva/daemon_creator.rb', line 16

def create
  error_exit("Please provide a daemon name. e.g. larva spawn my_daemon_name") if daemon_name.blank?
  error_exit("Directory #{daemon_dir} already exists. Please remove it before continuing.") if File.exists?(daemon_dir)

  # Copy template directory
  FileUtils.cp_r(template_dir, daemon_dir)
  rename_directories
  rename_files
  rename_file_contents
  alter_files if respond_to?(:alter_files)
  git_it_up
  $stdout.puts "Daemon '#{daemon_name}' created succesfully :)"
end