class Sequent::Generator::Project
Public Class Methods
Source
# File lib/sequent/generator/project.rb, line 10 def initialize(path_or_name) @path_or_name = path_or_name end
Public Instance Methods
Source
# File lib/sequent/generator/project.rb, line 14 def execute fail TargetAlreadyExists if File.exist?(path) make_directory copy_files rename_app_file replace_app_name end
Private Instance Methods
Source
# File lib/sequent/generator/project.rb, line 29 def copy_files FileUtils.copy_entry(File.expand_path('template_project', __dir__), path) ['.ruby-version', 'db'].each do |file| FileUtils.copy_entry(File.expand_path("../../../#{file}", __dir__), "#{path}/#{file}") end end
Source
# File lib/sequent/generator/project.rb, line 25 def make_directory FileUtils.mkdir_p(path) end
Source
# File lib/sequent/generator/project.rb, line 55 def name @name ||= File.basename(path) end
Source
# File lib/sequent/generator/project.rb, line 63 def name_camelized @name_camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize end
Source
# File lib/sequent/generator/project.rb, line 59 def name_underscored @name_underscored ||= name.underscore end
Source
# File lib/sequent/generator/project.rb, line 51 def path @path ||= File.expand_path(@path_or_name) end
Source
# File lib/sequent/generator/project.rb, line 36 def rename_app_file FileUtils.mv("#{path}/my_app.rb", "#{path}/#{name_underscored}.rb") end
Source
# File lib/sequent/generator/project.rb, line 40 def replace_app_name files = Dir["#{path}/**/*"].select { |f| File.file?(f) } files.each do |filename| contents = File.read(filename) contents.gsub!('my_app', name_underscored) contents.gsub!('MyApp', name_camelized) File.open(filename, 'w') { |f| f.puts contents } end end