Module: Nisetegami::ActionMailerExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/nisetegami/action_mailer_extensions.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #mail_with_template(headers = {}, &block) ⇒ Object
- #render_with_layout(*args, &block) ⇒ Object
- #testing(&block) ⇒ Object
Instance Method Details
#mail_with_template(headers = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nisetegami/action_mailer_extensions.rb', line 33 def mail_with_template(headers = {}, &block) # maybe there is better way? - do not want to do query it (despite cache is used) for second time @_ar_template = Template.by_mailer(self.class).by_action(action_name).first if @_ar_template self.action_name ||= @_ar_template.action.to_s # think about this ugly shit vars = instance_variables.inject({}) do |hsh, var| unless var =~ /@_/ template_var = instance_variable_get(var) if template_var.class != (casted = Nisetegami.cast[template_var.class]) template_var = instance_variable_set(var, casted.new(template_var)) end hsh[var[1..-1].to_sym] = template_var end hsh end headers.reverse_merge!(@_ar_template.headers(vars)) end mail_without_template(headers, &block).tap do |m| m.perform_deliveries = testing? || !@_ar_template || @_ar_template.enabled m.body = nil unless m.perform_deliveries # better to remove corresponding specs?? end end |
#render_with_layout(*args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/nisetegami/action_mailer_extensions.rb', line 23 def render_with_layout(*args, &block) = args.first if ![:layout] && @_ar_template format = [:template].identifier.split('.').last layout = @_ar_template.send("layout_#{format}") [:layout] = layout unless layout.blank? end render_without_layout(*args, &block) end |
#testing(&block) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/nisetegami/action_mailer_extensions.rb', line 57 def testing(&block) @_testing_was, @_testing = @_testing, true yield self ensure @_testing = @_testing_was end |