Class: Rack::Generator::Command

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/rack/generator/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



29
30
31
# File 'lib/rack/generator/command.rb', line 29

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#middleware(name, author, email, description) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rack/generator/command.rb', line 12

def middleware(name, author, email, description)
   @name = name.gsub(/\W/,'-').underscore.dasherize.gsub(/\Arack\-/, '')
   @constant = @name.gsub(/-/, '_').camelize
   @author = author
   @email = email
   @description = description

   templates_dir = Pathname.new("#{self.class.source_root}/../../templates/middleware").realpath.to_s
   templates = Dir.glob("#{templates_dir}/**/*.erb")

   templates.each do |template_path|
     rel_path = template_path.gsub(templates_dir, '')
     new_path = "#{Dir.pwd}#{rel_path}".gsub('NAME', @name).gsub(/\.erb\Z/, '')
     template template_path, new_path
   end
end