Sha256: d1d269a47a2003a19bade5ba39ebace479c3f5e0fa495a2a595f97ee47ea9584

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

= ActsAsMessageable
The Acts As Messageable allows communication between the models.

== Usage
To use it, add it to your Gemfile:

    gem 'acts-as-messageable'

== Post instalation

    rails g acts_as_messageable:migration [table_name] # default 'messages'
    rake db:migrate

== Usage

    class User < ActiveRecord::Base
        acts_as_messageable :table_name => "table_with_messages", # default 'messages'
                            :required   => :body                  # default [:topic, :body]
    end

== Send message

    @alice = User.first
    @bob   = User.last

    @alice.send_message(@bob, "Message topic", "Hi bob!")
    @bob.send_message(@alice, "Re: Message topic", "Hi alice!")

== New API
    @alice.messages -- all messages connected with @alice (inbox/outbox)
    @alice.deleted_messages -- all messages connected with @alice (trash)

    @alice.messages.are_from(@bob) -- all message form @bob
    @alice.messages.are_to(@bob) -- all message to @bob
    @alice.messages.id(@id_of_message) -- message with id id_of_message
    @alice.messages.readed -- all readed @alice  messages
    @alice.messages.unaded -- all unreaded @alice messages

    You can use multiple filters at the same time

    @alice.messages.are_from(@bob).are_to(@alice).readed -- all message from @bob to @alice and readed
    @alice.deleted_message.are_from(@bob) -- all deleted messages from @bob

=== Delete message

    @alice.messages.process do |message|
        message.delete
    end


Copyright © 2011 Piotr Niełacny (http://ruby-blog.pl), released under the MIT license

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts-as-messageable-0.2.0 README.rdoc