Sha256: 6a666d958eb36a22868b1020d461f5a3d27d865edfe00f56f27e4b6950aa0852

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

module Maily
  module Generators
    class InstallGenerator < Rails::Generators::Base
      desc 'Maily installation: route and initializer'
      source_root File.expand_path("../../templates", __FILE__)

      def install
        generate_routing
        build_initializer
        build_hooks
      end

      private

      def generate_routing
        route "mount Maily::Engine, at: 'maily'"
      end

      def build_initializer
        template 'initializer.rb', 'config/initializers/maily.rb'
      end

      def build_hooks
        fixtures = []
        hooks    = []

        Maily::Mailer.all.each do |mailer|
          hooks << "\nMaily.hooks_for('#{mailer.name.classify}') do |mailer|"
          mailer.emails.each do |email|
            if email.require_hook?
              fixtures << email.required_arguments
              hooks << "  mailer.register_hook(:#{email.name}, #{email.required_arguments.join(', ')})"
            end
          end
          hooks << "end"
        end

        create_file "lib/maily_hooks.rb" do
          fixtures.flatten.uniq.map{ |f| f = "#{f.to_s} = ''" }.join("\n") + "\n" + hooks.join("\n") + "\n"
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
maily-0.6.0 lib/generators/maily/install_generator.rb
maily-0.5.0 lib/generators/maily/install_generator.rb
maily-0.4.0 lib/generators/maily/install_generator.rb
maily-0.3.5 lib/generators/maily/install_generator.rb
maily-0.3.4 lib/generators/maily/install_generator.rb
maily-0.3.3 lib/generators/maily/install_generator.rb
maily-0.3.2 lib/generators/maily/install_generator.rb
maily-0.3.1 lib/generators/maily/install_generator.rb
maily-0.3.0 lib/generators/maily/install_generator.rb