Sha256: a33f451b7b7c1c9abb4f621491f4fe1ad63e15ab6c6afbf9861f3e49c0a3a78e
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
module Maily class Email attr_accessor :name, :mailer, :arguments, :template_path def initialize(name, mailer) self.name = name.to_s self.mailer = mailer self.arguments = nil self.template_path = mailer end def parameters mailer_klass.instance_method(name).parameters end def require_hook? parameters.any? end def required_arguments parameters.map(&:last) end 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 def mailer_klass_name mailer.camelize end def mailer_klass mailer_klass_name.constantize end def call mailer_klass.send(name, *arguments) end def base_path(part) "#{Rails.root}/app/views/#{template_path}/#{name}.#{part}.erb" end 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 def template(part = nil) File.read(path(part)) end def update_template(new_content, part = nil) File.open(path(part), 'w') do |f| f.write(new_content) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
maily-0.5.0 | lib/maily/email.rb |