Sha256: dcf222660981d81a787692d262f7ef10923f9cd773ea056175fabb2e7a210efe

Contents?: true

Size: 859 Bytes

Versions: 1

Compression:

Stored size: 859 Bytes

Contents

module ActionTexter
  class Message
    attr_accessor :to, :from, :body

    attr_accessor :delivery_handler, :perform_deliveries, :raise_delivery_errors
    attr_reader :delivery_method, :delivery_options

    def initialize(attrs = {})
      attrs.each do |k, v|
        self.send("#{k}=", v) if self.respond_to?("#{k}=")
      end
    end

    def []=(k, v)
      self.send("#{k}=", v) if self.respond_to?("#{k}=")
    end

    def [](k)
      self.send(k) if self.respond_to?(k)
    end

    def deliver
      return false unless perform_deliveries
      begin
        @delivery_method.deliver(self)
      rescue => e
        raise e if raise_delivery_errors
      end
    end

    def delivery_method(method = nil, opts = {})
      unless method
        @delivery_method
      else
        @delivery_method = method.new(opts)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
actiontexter-0.1.0 lib/action_texter/message.rb