Module: Maily::Generator

Defined in:
lib/maily/generator.rb

Class Method Summary collapse

Class Method Details

.runObject



3
4
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
# File 'lib/maily/generator.rb', line 3

def self.run
  Maily.init!

  fixtures = []
  hooks    = []

  Maily::Mailer.list.each do |mailer|
    _hooks = []

    mailer.emails_list.each do |email|
      if email.require_hook?
        fixtures << email.required_arguments
        _hooks << "  mailer.register_hook(:#{email.name}, #{email.required_arguments.join(', ')})"
      end
    end

    if _hooks.present?
      hooks << "\nMaily.hooks_for('#{mailer.name.classify}') do |mailer|"
      hooks << _hooks
      hooks << "end"
    end
  end

  fixtures = fixtures.flatten.uniq.map { |f| "#{f.to_s} = ''" }.join("\n")
  hooks    = hooks.join("\n")

  fixtures + "\n" + hooks + "\n"
end