Class: Appifier::Actors::Generator

Inherits:
Object
  • Object
show all
Extended by:
Carioca::Injector
Defined in:
lib/appifier/actors/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_root:, target_root:, dataset:) ⇒ Generator

Returns a new instance of Generator.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/appifier/actors/generator.rb', line 12

def initialize(template_root:, target_root:, dataset: )
  @template_root = template_root
  @src_root = "#{template_root}/skeleton"
  @target_root = target_root
  @target_folders = []
  @target_files = []
  @data = dataset
  @src_paths = Dir.glob("#{@src_root}/**/*", File::FNM_DOTMATCH)
  @src_paths.delete_if { |file| file =~ %r{/\.$} }
  @src_folders = @src_paths.select { |item| File.directory? item }
  @src_files = @src_paths.select { |item| File.file? item }
  raise 'Application template not found' unless File.exist?(@template_root)
end

Instance Attribute Details

#src_filesObject (readonly)

Returns the value of attribute src_files.



6
7
8
# File 'lib/appifier/actors/generator.rb', line 6

def src_files
  @src_files
end

#src_foldersObject (readonly)

Returns the value of attribute src_folders.



6
7
8
# File 'lib/appifier/actors/generator.rb', line 6

def src_folders
  @src_folders
end

#src_pathsObject (readonly)

Returns the value of attribute src_paths.



6
7
8
# File 'lib/appifier/actors/generator.rb', line 6

def src_paths
  @src_paths
end

#target_filesObject (readonly)

Returns the value of attribute target_files.



6
7
8
# File 'lib/appifier/actors/generator.rb', line 6

def target_files
  @target_files
end

#target_foldersObject (readonly)

Returns the value of attribute target_folders.



6
7
8
# File 'lib/appifier/actors/generator.rb', line 6

def target_folders
  @target_folders
end

Instance Method Details

#calculateObject



38
39
40
41
# File 'lib/appifier/actors/generator.rb', line 38

def calculate
  calculate_target type: :folder
  calculate_target type: :file
end

#generate(dry_run: false, force: false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appifier/actors/generator.rb', line 26

def generate(dry_run: false, force: false)
  output.info 'Running in dry_run (operation will be SKIPPED)' if dry_run
  calculate
   raise 'Folders and files already exist'  if check_folder_already_exist && !force
  FileUtils.rm_rf("#{@target_root}/#{@target_folders.first}") if force
  output.info 'Generate folders'
  generate_folders dry_run: dry_run
  output.info 'Generate files'
  generate_files dry_run: dry_run
  copy_appifile dry_run: dry_run
end