class Pliny::Commands::Creator
Attributes
Public Class Methods
Source
# File lib/pliny/commands/creator.rb, line 16 def initialize(args = {}, opts = {}, stream = $stdout) @args = args @opts = opts @stream = stream end
Source
# File lib/pliny/commands/creator.rb, line 12 def self.run(args, opts = {}, stream = $stdout) new(args, opts, stream).run! end
Public Instance Methods
Source
# File lib/pliny/commands/creator.rb, line 22 def run! abort("#{name} already exists") if File.exist?(app_dir) FileUtils.copy_entry template_dir, app_dir FileUtils.rm_rf("#{app_dir}/.git") parse_erb_files display 'Pliny app created. To start, run:' display "cd #{app_dir} && bin/setup" end
Protected Instance Methods
Source
# File lib/pliny/commands/creator.rb, line 61 def app_dir Pathname.new(name).expand_path end
Source
# File lib/pliny/commands/creator.rb, line 49 def display(msg) stream.puts msg end
Source
# File lib/pliny/commands/creator.rb, line 34 def parse_erb_files Dir.glob("#{app_dir}/{*,.*}.erb").each do |file| static_file = file.gsub(/\.erb$/, '') template = ERB.new(File.read(file)) context = OpenStruct.new(app_name: name) content = template.result(context.instance_eval { binding }) File.open(static_file, "w") do |f| f.write content end FileUtils.rm(file) end end
Source
# File lib/pliny/commands/creator.rb, line 57 def template_dir File.expand_path('../../template', File.dirname(__FILE__)) end