Class: Appifier::Actors::Generator
- Inherits:
-
Object
- Object
- Appifier::Actors::Generator
- Defined in:
- lib/appifier/actors/generator.rb
Instance Attribute Summary collapse
-
#src_files ⇒ Object
readonly
Returns the value of attribute src_files.
-
#src_folders ⇒ Object
readonly
Returns the value of attribute src_folders.
-
#src_paths ⇒ Object
readonly
Returns the value of attribute src_paths.
-
#target_files ⇒ Object
readonly
Returns the value of attribute target_files.
-
#target_folders ⇒ Object
readonly
Returns the value of attribute target_folders.
Instance Method Summary collapse
- #calculate ⇒ Object
- #generate(dry_run: false, force: false) ⇒ Object
-
#initialize(src_root:, target_root:) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(src_root:, target_root:) ⇒ Generator
Returns a new instance of Generator.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/appifier/actors/generator.rb', line 8 def initialize(src_root:, target_root:) @src_root = src_root @target_root = target_root @target_folders = [] @target_files = [] @data = { appname: 'test' } @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 } end |
Instance Attribute Details
#src_files ⇒ Object (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_folders ⇒ Object (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_paths ⇒ Object (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_files ⇒ Object (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_folders ⇒ Object (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
#calculate ⇒ Object
34 35 36 37 |
# File 'lib/appifier/actors/generator.rb', line 34 def calculate calculate_target type: :folder calculate_target type: :file end |
#generate(dry_run: false, force: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/appifier/actors/generator.rb', line 20 def generate(dry_run: false, force: false) puts 'Running in dry_run' if dry_run calculate if check_folder_already_exist && !force puts 'Folders and files already exist' return false end FileUtils.rm_rf("#{@target_root}/#{@target_folders.first}") if force puts 'Generate folders' generate_folders dry_run: dry_run puts 'Generate files' generate_files dry_run: dry_run end |