class Slappy::Commands::Generator
Public Instance Methods
call(dir_name)
click to toggle source
# File lib/slappy/commands/generator.rb, line 4 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 mkdir lib_dir_path copy template_script_path, scripts_dir_path copy config_file_path, target_dir end
Private Instance Methods
config_file_path()
click to toggle source
# File lib/slappy/commands/generator.rb, line 39 def config_file_path File.expand_path Slappy.configuration.config_file_path, template_dir end
copy(src, dest)
click to toggle source
# File lib/slappy/commands/generator.rb, line 51 def copy(src, dest) path = File.expand_path File.basename(src), dest generate(path) { FileUtils.cp src, dest } end
gem_root_dir()
click to toggle source
# File lib/slappy/commands/generator.rb, line 23 def gem_root_dir File.expand_path '../../../../', __FILE__ end
generate(target, &block)
click to toggle source
# File lib/slappy/commands/generator.rb, line 63 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
lib_dir_path()
click to toggle source
# File lib/slappy/commands/generator.rb, line 31 def lib_dir_path File.expand_path Slappy.configuration.lib_dir_path, target_dir end
mkdir(path)
click to toggle source
# File lib/slappy/commands/generator.rb, line 47 def mkdir(path) generate(path) { FileUtils.mkdir path } end
put_result(result, target)
click to toggle source
# File lib/slappy/commands/generator.rb, line 74 def put_result(result, target) puts "\t#{result}\t#{target}" end
scripts_dir_path()
click to toggle source
# File lib/slappy/commands/generator.rb, line 35 def scripts_dir_path File.expand_path Slappy.configuration.scripts_dir_path, target_dir end
status()
click to toggle source
# File lib/slappy/commands/generator.rb, line 56 def status @messages = { create: TermColor.parse('<green>create</green>'), exist: TermColor.parse('<red>exist</red>') } end
target_dir()
click to toggle source
# File lib/slappy/commands/generator.rb, line 19 def target_dir File.expand_path @target_dir, Dir.pwd end
template_dir()
click to toggle source
# File lib/slappy/commands/generator.rb, line 27 def template_dir File.expand_path 'templates', gem_root_dir end
template_script_path()
click to toggle source
# File lib/slappy/commands/generator.rb, line 43 def template_script_path File.expand_path 'example.rb', template_dir end