Module: Maily

Defined in:
lib/maily.rb,
lib/maily/email.rb,
lib/maily/engine.rb,
lib/maily/mailer.rb,
lib/maily/version.rb,
app/helpers/maily/emails_helper.rb,
app/helpers/maily/application_helper.rb,
lib/generators/maily/install_generator.rb,
app/controllers/maily/emails_controller.rb,
app/controllers/maily/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, EmailsHelper, Generators Classes: ApplicationController, Email, EmailsController, Engine, Mailer

Constant Summary collapse

VERSION =
"0.6.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allow_deliveryObject

Returns the value of attribute allow_delivery.



8
9
10
# File 'lib/maily.rb', line 8

def allow_delivery
  @allow_delivery
end

.allow_editionObject

Returns the value of attribute allow_edition.



8
9
10
# File 'lib/maily.rb', line 8

def allow_edition
  @allow_edition
end

.available_localesObject

Returns the value of attribute available_locales.



8
9
10
# File 'lib/maily.rb', line 8

def available_locales
  @available_locales
end

.base_controllerObject

Returns the value of attribute base_controller.



8
9
10
# File 'lib/maily.rb', line 8

def base_controller
  @base_controller
end

.enabledObject

Returns the value of attribute enabled.



8
9
10
# File 'lib/maily.rb', line 8

def enabled
  @enabled
end

.hooks_pathObject

Returns the value of attribute hooks_path.



8
9
10
# File 'lib/maily.rb', line 8

def hooks_path
  @hooks_path
end

.http_authorizationObject

Returns the value of attribute http_authorization.



8
9
10
# File 'lib/maily.rb', line 8

def http_authorization
  @http_authorization
end

.welcome_messageObject

Returns the value of attribute welcome_message.



8
9
10
# File 'lib/maily.rb', line 8

def welcome_message
  @welcome_message
end

Class Method Details

.allowed_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
# File 'lib/maily.rb', line 46

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

.hooks_for(mailer_name) {|mailer| ... } ⇒ Object

Yields:

  • (mailer)


36
37
38
39
# File 'lib/maily.rb', line 36

def hooks_for(mailer_name)
  mailer = Maily::Mailer.find(mailer_name.underscore)
  yield(mailer) if block_given?
end

.init!Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/maily.rb', line 11

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  = 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

.load_emails_and_hooksObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/maily.rb', line 22

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')
    klass = klass_name.camelize.constantize
    methods = klass.send(:public_instance_methods, false)
    Maily::Mailer.new(klass_name, methods)
  end

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

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Maily)

    the object that the method was called on



41
42
43
44
# File 'lib/maily.rb', line 41

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