Class: Makanai::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/makanai/generator.rb

Constant Summary collapse

ROOT_PATH =
"#{Makanai.root}/lib/makanai/generator".freeze
DIRECTORY_NAMES =
YAML.load_file("#{ROOT_PATH}/application/directories.yaml")
APP_TEMPLATE =
File.read("#{ROOT_PATH}/application/templates/app.erb")
RAKEFILE_TEMPLATE =
File.read("#{ROOT_PATH}/application/templates/rakefile.erb")
GEMFILE_TEMPLATE =
File.read("#{ROOT_PATH}/application/templates/gemfile.erb")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = Dir.pwd) ⇒ Generator

Returns a new instance of Generator.



15
16
17
# File 'lib/makanai/generator.rb', line 15

def initialize(path = Dir.pwd)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



19
20
21
# File 'lib/makanai/generator.rb', line 19

def path
  @path
end

Instance Method Details

#create_app_directories(directory_names = DIRECTORY_NAMES) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/makanai/generator.rb', line 21

def create_app_directories(directory_names = DIRECTORY_NAMES)
  directory_names.map do |name|
    dir_path = File.join(path, name)
    Dir.mkdir(dir_path)
    file_path = File.join(dir_path, '.keep')
    create_file(file_path, nil)
    file_path
  end
end

#create_app_rb(template = APP_TEMPLATE) ⇒ Object



31
32
33
34
35
# File 'lib/makanai/generator.rb', line 31

def create_app_rb(template = APP_TEMPLATE)
  File.join(path, 'app.rb').tap do |file_path|
    create_file(file_path, ERB.new(template).result)
  end
end

#create_gemfile(template = GEMFILE_TEMPLATE) ⇒ Object



43
44
45
46
47
# File 'lib/makanai/generator.rb', line 43

def create_gemfile(template = GEMFILE_TEMPLATE)
  File.join(path, 'Gemfile').tap do |file_path|
    create_file(file_path, ERB.new(template).result)
  end
end

#create_rakefile(template = RAKEFILE_TEMPLATE) ⇒ Object



37
38
39
40
41
# File 'lib/makanai/generator.rb', line 37

def create_rakefile(template = RAKEFILE_TEMPLATE)
  File.join(path, 'Rakefile').tap do |file_path|
    create_file(file_path, ERB.new(template).result)
  end
end