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.3.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allow_deliveryObject

Returns the value of attribute allow_delivery.



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

def allow_delivery
  @allow_delivery
end

.allow_editionObject

Returns the value of attribute allow_edition.



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

def allow_edition
  @allow_edition
end

.available_localesObject

Returns the value of attribute available_locales.



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

def available_locales
  @available_locales
end

.base_controllerObject

Returns the value of attribute base_controller.



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

def base_controller
  @base_controller
end

.enabledObject

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

Class Method Details

.allowed_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
# File 'lib/maily.rb', line 42

def allowed_action?(action)
  case action.to_sym
  when :edit, :update
    allow_edition
  when :deliver
    allow_delivery
  end
end

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

Yields:

  • (mailer)


32
33
34
35
# File 'lib/maily.rb', line 32

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

def init!
  self.enabled           = true
  self.allow_edition     = true
  self.allow_delivery    = true
  self.available_locales = I18n.available_locales
  self.base_controller   = 'ActionController::Base'
end

.load_emails_and_hooksObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/maily.rb', line 19

def load_emails_and_hooks
  # Load emails
  Dir[Rails.root + 'app/mailers/*.rb'].each do |mailer|
    klass   = File.basename(mailer, '.rb')
    methods = klass.camelize.constantize.send(:instance_methods, false)
    Maily::Mailer.new(klass, methods)
  end

  # Load hooks
  hooks_file_path = "#{Rails.root}/lib/maily_hooks.rb"
  require hooks_file_path if File.exists?(hooks_file_path)
end

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

Yields:

  • (_self)

Yield Parameters:

  • _self (Maily)

    the object that the method was called on



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

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