Sha256: 5c2525ebab3be801b11fc9042eeee3f8eb45c178ea512fb33081a10f77aa3ddb

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

module Macaco
  class Sender

    def initialize(*args, &block)
      @body_html = nil
      @body_text = nil
      @text      = nil
      @to        = []
      @from      = nil
      @subject   = nil

      if args.first.is_a? Hash
        hash_attributes(args.first)
      end

      if block_given?
        instance_eval(&block)
      end

      self
    end

    def hash_attributes(args)
      to      args[:to]
      from    args[:from]
      subject args[:subject]
      body_html args[:body_html]
      body_text args[:body_text]
    end

    def to(val = nil)
      return @to unless val
      @to << { email: val }
    end

    def from(val = nil)
      return @from unless val
      @from ||= val
    end

    def subject(val = nil)
      return @subject unless val
      @subject ||= val
    end

    def body_html(val = nil)
      return @body_html unless val
      @body_html ||= val
    end
    alias_method :html, :body_html

    def body_text(val = nil)
      return @body_text unless val
      @body_text ||= val
    end
    alias_method :text, :body_text

    # helpers - could be split out?

    def to_json
      to_hash.to_json
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
macaco-0.0.4 lib/macaco/senders/sender.rb
macaco-0.0.3 lib/macaco/senders/sender.rb
macaco-0.0.2 lib/macaco/senders/sender.rb