class Sequent::Generator::Project

Public Class Methods

new(path_or_name) click to toggle source
# File lib/sequent/generator/project.rb, line 10
def initialize(path_or_name)
  @path_or_name = path_or_name
end

Public Instance Methods

execute() click to toggle source
# File lib/sequent/generator/project.rb, line 14
def execute
  make_directory
  copy_files
  rename_ruby_version
  rename_app_file
  replace_app_name
end

Private Instance Methods

copy_files() click to toggle source
# File lib/sequent/generator/project.rb, line 28
def copy_files
  FileUtils.copy_entry(File.expand_path('template_project', __dir__), path)
end
make_directory() click to toggle source
# File lib/sequent/generator/project.rb, line 24
def make_directory
  FileUtils.mkdir_p(path)
end
name() click to toggle source
# File lib/sequent/generator/project.rb, line 57
def name
  @name ||= File.basename(path)
end
name_camelized() click to toggle source
# File lib/sequent/generator/project.rb, line 65
def name_camelized
  @name_camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
end
name_underscored() click to toggle source
# File lib/sequent/generator/project.rb, line 61
def name_underscored
  @name_underscored ||= name.underscore
end
path() click to toggle source
# File lib/sequent/generator/project.rb, line 53
def path
  @path ||= File.expand_path(@path_or_name)
end
rename_app_file() click to toggle source
# File lib/sequent/generator/project.rb, line 38
def rename_app_file
  FileUtils.mv("#{path}/my_app.rb", "#{path}/#{name_underscored}.rb")
end
rename_ruby_version() click to toggle source

Hidden files are by default excluded from gem build. Therefor we need to rename the ruby-version to .ruby-version.

# File lib/sequent/generator/project.rb, line 34
def rename_ruby_version
  FileUtils.mv("#{path}/ruby-version", "#{path}/.ruby-version")
end
replace_app_name() click to toggle source
# File lib/sequent/generator/project.rb, line 42
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