Class: Bushido::Generators::MailRoutesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/bushido/mail_routes_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_mail_routes_fileObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/bushido/mail_routes_generator.rb', line 5

def create_mail_routes_file
  # Create the lib/bushido directory if it doesnt exist
  Dir.mkdir("#{Rails.root}/lib/bushido") if not Dir.exists? "#{Rails.root}/lib/bushido"
  
  lib "bushido/mail_routes.rb" do
    <<-EOF
::Bushido::Mailroute.map do |m|

  m.route("simple") do
    m.subject("hello")
  end

end
    EOF
  end

  lib("bushido/hooks/email_hooks.rb") do
    <<-EOF
class BushidoEmailHooks < Bushido::EventObserver

  def mail_simple
    puts "YAY!"
    puts params.inspect
  end

end
    EOF
  end
  
  initializer "bushido_hooks.rb" do
    <<-EOF
Dir["\#{Dir.pwd}/lib/bushido/**/*.rb"].each { |file| require file }
    EOF
  end
  
  initializer("bushido_mail_routes.rb", "require './lib/bushido/mail_routes.rb'")

end