Class: Makanai::Generator
- Inherits:
-
Object
- Object
- Makanai::Generator
- Defined in:
- lib/makanai/generator.rb
Constant Summary collapse
- ROOT_PATH =
"#{Makanai.root}/lib/makanai/generator"
- 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")
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #create_app_directories(directory_names = DIRECTORY_NAMES) ⇒ Object
- #create_app_rb(template = APP_TEMPLATE) ⇒ Object
- #create_rakefile(template = RAKEFILE_TEMPLATE) ⇒ Object
-
#initialize(path = Dir.pwd) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(path = Dir.pwd) ⇒ Generator
Returns a new instance of Generator.
14 15 16 |
# File 'lib/makanai/generator.rb', line 14 def initialize(path = Dir.pwd) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/makanai/generator.rb', line 18 def path @path end |
Instance Method Details
#create_app_directories(directory_names = DIRECTORY_NAMES) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/makanai/generator.rb', line 20 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
30 31 32 33 34 |
# File 'lib/makanai/generator.rb', line 30 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_rakefile(template = RAKEFILE_TEMPLATE) ⇒ Object
36 37 38 39 40 |
# File 'lib/makanai/generator.rb', line 36 def create_rakefile(template = RAKEFILE_TEMPLATE) File.join(path, 'Rakefile').tap do |file_path| create_file(file_path, ERB.new(template).result) end end |