Sha256: e5d414280163e60ebb8af0437ae60ee2f39f5752d71a18c50cbb2d87e9b4dbc4
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
module Slappy module Commands class Generator def call(dir_name) dir_name = './' if dir_name.nil? dir_name += '/' if !dir_name.nil? && dir_name.split('').last != '/' @target_dir = dir_name mkdir target_dir unless @target_dir.nil? mkdir scripts_dir_path copy template_script_path, scripts_dir_path copy config_file_path, target_dir end private def target_dir File.expand_path @target_dir, Dir.pwd end def gem_root_dir File.expand_path '../../../../', __FILE__ end def template_dir File.expand_path 'templates', gem_root_dir end def scripts_dir_path File.expand_path Slappy.configuration.scripts_dir_path, target_dir end def config_file_path File.expand_path Slappy.configuration.config_file_path, template_dir end def template_script_path File.expand_path 'example.rb', template_dir end def mkdir(path) generate(path) { FileUtils.mkdir path } end def copy(src, dest) path = File.expand_path File.basename(src), dest generate(path) { FileUtils.cp src, dest } end def status @messages = { create: TermColor.parse('<green>create</green>'), exist: TermColor.parse('<red>exist</red>') } end def generate(target, &block) if FileTest.exist? target result = status[:exist] else block.call result = status[:create] end put_result result, Pathname.new(target).relative_path_from(Pathname.new(Dir.pwd)) end def put_result(result, target) puts "\t#{result}\t#{target}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slappy-0.3.0 | lib/slappy/commands/generator.rb |