Module: Skeleton
- Defined in:
- lib/asker/skeleton.rb
Overview
Skeleton: create skeleton for asker input files
-
create
-
create_main_dir_and_files
-
create_dir
-
create_dirs
-
copyfile
Class Method Summary collapse
- .copy_files_into(project_dir) ⇒ Object
- .copyfile(target, dest) ⇒ Object
- .create(dirpath) ⇒ Object
- .create_dir(dirpath) ⇒ Object
- .create_dirs(*args) ⇒ Object
Class Method Details
.copy_files_into(project_dir) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/asker/skeleton.rb', line 19 def self.copy_files_into(project_dir) # Directory and files: Ruby script, Configfile, gitignore items = [ { source: 'files/example-concept.haml', target: 'example-concept.haml' } # { source: 'files/example-code.haml', target: 'example-code.haml' }, ] source_basedir = File.join(File.dirname(__FILE__)) items.each do |item| source = File.join(source_basedir, item[:source]) target = File.join(project_dir, item[:target]) copyfile(source, target) end end |
.copyfile(target, dest) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/asker/skeleton.rb', line 50 def self.copyfile(target, dest) if File.exist? dest puts "* Exists file! => #{Rainbow(dest).yellow}" else puts "* File not found! => #{Rainbow(target).yellow}" unless File.exist? target begin FileUtils.cp(target, dest) puts "* Create file => #{Rainbow(dest).green}" rescue StandardError puts "* Create file ERROR => #{Rainbow(dest).red}" end end end |
.create(dirpath) ⇒ Object
13 14 15 16 17 |
# File 'lib/asker/skeleton.rb', line 13 def self.create(dirpath) puts "\n[INFO] Creating #{Rainbow(dirpath).bright} project skeleton" create_dir dirpath copy_files_into(dirpath) end |
.create_dir(dirpath) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/asker/skeleton.rb', line 33 def self.create_dir(dirpath) if Dir.exist? dirpath puts "* Exists dir! => #{Rainbow(dirpath).yellow}" else begin FileUtils.mkdir_p(dirpath) puts "* Create dir => #{Rainbow(dirpath).green}" rescue StandardError puts "* Create dir ERROR => #{Rainbow(dirpath).red}" end end end |
.create_dirs(*args) ⇒ Object
46 47 48 |
# File 'lib/asker/skeleton.rb', line 46 def self.create_dirs(*args) args.each { |arg| create_dir arg } end |