Sha256: 21133125b5a2977261f11a6b07ff75213671f4d5135629763a23795c8bc6dfce
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 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 require_hook? mailer_klass.instance_method(name).parameters.any? end def required_arguments mailer_klass.instance_method(name).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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
maily-0.3.2 | lib/maily/email.rb |
maily-0.3.1 | lib/maily/email.rb |
maily-0.3.0 | lib/maily/email.rb |