Class: Cloudfuji::Generators::MailRoutesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/cloudfuji/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/cloudfuji/mail_routes_generator.rb', line 5

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

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

end
    EOF
  end

  lib("cloudfuji/hooks/email_hooks.rb") do
    <<-EOF
class CloudfujiEmailHooks < Cloudfuji::EventObserver

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

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

end