Class: Rivendell::Import::Notifier::Mail

Inherits:
Base
  • Object
show all
Defined in:
lib/rivendell/import/notifier/mail.rb

Defined Under Namespace

Classes: Message

Constant Summary collapse

@@from =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#delay, #logger, #notify, notify, #parameters=, #parameters_hash, #raw_parameters, #read_parameters, #write_parameters

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/rivendell/import/notifier/mail.rb', line 10

def body
  @body
end

#fromObject

Returns the value of attribute from.



10
11
12
# File 'lib/rivendell/import/notifier/mail.rb', line 10

def from
  @from
end

#subjectObject

Returns the value of attribute subject.



10
11
12
# File 'lib/rivendell/import/notifier/mail.rb', line 10

def subject
  @subject
end

#toObject

Returns the value of attribute to.



10
11
12
# File 'lib/rivendell/import/notifier/mail.rb', line 10

def to
  @to
end

Instance Method Details

#create_message(tasks) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/rivendell/import/notifier/mail.rb', line 28

def create_message(tasks)
  Message.new(tasks).tap do |mail|
    mail.from = from
    mail.to = to
    mail.subject = template(subject)
    mail.body = template(body)
  end
end

#notify!(tasks) ⇒ Object



24
25
26
# File 'lib/rivendell/import/notifier/mail.rb', line 24

def notify!(tasks)
  create_message(tasks).deliver!
end

#parametersObject

def valid?

[from, to, subject, body].all?(&:present?)

end



87
88
89
90
91
92
93
# File 'lib/rivendell/import/notifier/mail.rb', line 87

def parameters
  %w{from to subject body}.inject({}) do |map, attribute|
    value = send attribute
    map[attribute] = value if value
    map
  end
end

#template(definition) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/rivendell/import/notifier/mail.rb', line 95

def template(definition)
  if File.exists?(definition)
    File.read definition
  else
    definition
  end
end