Class: Maily::Email
- Inherits:
-
Object
- Object
- Maily::Email
- Defined in:
- lib/maily/email.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#mailer ⇒ Object
Returns the value of attribute mailer.
-
#name ⇒ Object
Returns the value of attribute name.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Instance Method Summary collapse
- #base_path(part) ⇒ Object
- #call ⇒ Object
-
#initialize(name, mailer) ⇒ Email
constructor
A new instance of Email.
- #mailer_klass ⇒ Object
- #mailer_klass_name ⇒ Object
- #path(part = nil) ⇒ Object
- #register_hook(*args) ⇒ Object
- #require_hook? ⇒ Boolean
- #required_arguments ⇒ Object
- #template(part = nil) ⇒ Object
- #update_template(new_content, part = nil) ⇒ Object
Constructor Details
#initialize(name, mailer) ⇒ Email
Returns a new instance of Email.
6 7 8 9 10 11 |
# File 'lib/maily/email.rb', line 6 def initialize(name, mailer) self.name = name.to_s self.mailer = mailer self.arguments = nil self.template_path = mailer end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/maily/email.rb', line 4 def arguments @arguments end |
#mailer ⇒ Object
Returns the value of attribute mailer.
4 5 6 |
# File 'lib/maily/email.rb', line 4 def mailer @mailer end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/maily/email.rb', line 4 def name @name end |
#template_path ⇒ Object
Returns the value of attribute template_path.
4 5 6 |
# File 'lib/maily/email.rb', line 4 def template_path @template_path end |
Instance Method Details
#base_path(part) ⇒ Object
44 45 46 |
# File 'lib/maily/email.rb', line 44 def base_path(part) "#{Rails.root}/app/views/#{template_path}/#{name}.#{part}.erb" end |
#call ⇒ Object
40 41 42 |
# File 'lib/maily/email.rb', line 40 def call mailer_klass.send(name, *arguments) end |
#mailer_klass ⇒ Object
36 37 38 |
# File 'lib/maily/email.rb', line 36 def mailer_klass mailer_klass_name.constantize end |
#mailer_klass_name ⇒ Object
32 33 34 |
# File 'lib/maily/email.rb', line 32 def mailer_klass_name mailer.camelize end |
#path(part = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/maily/email.rb', line 48 def path(part = nil) if part base_path(part) else if File.exist?(path('html')) base_path('html') else base_path('text') end end end |
#register_hook(*args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/maily/email.rb', line 21 def register_hook(*args) args = args.flatten if args.last.is_a?(Hash) && new_path = args.last.delete(:template_path) self.template_path = new_path args.pop end self.arguments = args end |
#require_hook? ⇒ Boolean
13 14 15 |
# File 'lib/maily/email.rb', line 13 def require_hook? mailer_klass.instance_method(name).parameters.any? end |
#required_arguments ⇒ Object
17 18 19 |
# File 'lib/maily/email.rb', line 17 def required_arguments mailer_klass.instance_method(name).parameters.map(&:last) end |
#template(part = nil) ⇒ Object
60 61 62 |
# File 'lib/maily/email.rb', line 60 def template(part = nil) File.read(path(part)) end |
#update_template(new_content, part = nil) ⇒ Object
64 65 66 67 68 |
# File 'lib/maily/email.rb', line 64 def update_template(new_content, part = nil) File.open(path(part), 'w') do |f| f.write(new_content) end end |