Sha256: 64d5b12cb59062e311390360667a59265818dbafab71e345e267cc1128ff00ac

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

require 'maily/version'
require 'maily/engine'
require 'maily/mailer'
require 'maily/email'
require 'maily/generator'

module Maily
  class << self
    attr_accessor :enabled, :allow_edition, :allow_delivery, :available_locales,
                  :base_controller, :http_authorization, :hooks_path, :welcome_message

    def init!
      self.enabled            = Rails.env.production? ? false : true
      self.allow_edition      = Rails.env.production? ? false : true
      self.allow_delivery     = Rails.env.production? ? false : true
      self.available_locales  = Rails.application.config.i18n.available_locales || I18n.available_locales
      self.base_controller    = 'ActionController::Base'
      self.http_authorization = nil
      self.hooks_path         = "lib/maily_hooks.rb"
      self.welcome_message    = "Use the menu on the left hand side of the screen to navigate through the different email templates."
    end

    def load_emails_and_hooks
      # Load emails from file system
      Dir[Rails.root + 'app/mailers/*.rb'].each do |mailer|
        klass_name = File.basename(mailer, '.rb')
        Maily::Mailer.new(klass_name)
      end

      # Load hooks
      hooks_file_path = File.join(Rails.root, hooks_path)
      require hooks_file_path if File.exist?(hooks_file_path)
    end

    def hooks_for(mailer_name)
      mailer = Maily::Mailer.find(mailer_name.underscore)
      return unless mailer

      yield(mailer) if block_given?
    end

    def setup
      init!
      yield(self) if block_given?
    end

    def allowed_action?(action)
      case action.to_sym
      when :edit
        allow_edition
      when :update
        allow_edition && !Rails.env.production?
      when :deliver
        allow_delivery
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
maily-0.8.2 lib/maily.rb
maily-0.8.1 lib/maily.rb
maily-0.8.0 lib/maily.rb