Class: Rail::Generator

Inherits:
Support::Generator show all
Defined in:
lib/rail/generator.rb

Constant Summary collapse

FILES =
[
  'app/assets/javascripts/application.js.coffee',
  'app/assets/stylesheets/application.css.scss',
  'app/helpers/application_helper.rb',
  'app/views/layouts/application.html.haml.erb',
  'config/application.rb.erb',
  'config.ru.erb',
  'Gemfile',
  'public/favicon.png',
  'Rakefile.erb',
]

Instance Attribute Summary

Attributes inherited from Support::Generator

#destination, #source

Instance Method Summary collapse

Methods inherited from Support::Generator

#process

Constructor Details

#initialize(options) ⇒ Generator

Returns a new instance of Generator.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rail/generator.rb', line 18

def initialize(options)
  destination = options.fetch(:destination)
  source = File.expand_path('../templates', __FILE__)

  directory = destination.split('/').last || ''
  project_name = Support::Inflector.titelize(directory)
  class_name = project_name.gsub(' ', '')

  @locals = { class_name: class_name, project_name: project_name }

  raise ArgumentError, 'The project name is invalid.' if class_name.empty?

  super(destination: destination, source: source)
end

Instance Method Details

#runObject



33
34
35
36
37
38
# File 'lib/rail/generator.rb', line 33

def run
  if File.directory?(destination)
    raise ArgumentError, 'The directory already exists.'
  end
  process(FILES, @locals)
end