Skip to content

Latest commit

 

History

History
112 lines (72 loc) · 2.96 KB

README.mkdn

File metadata and controls

112 lines (72 loc) · 2.96 KB

Mezu

Code Climate Build Status Coverage Status

Mezu is a Rails 3 Engine to manage system messages globally, or for a specific object.

How to Install?

It's a piece of cake!

Add on your Gemfile

gem "mezu"

Install gem

$ bundle install # Of course, you can execute `gem install mezu`

Run Mezu generator

rails generate mezu:install

Run migrations

rake db:migrate

What does mezu:install generate?

This step create some files on your Rails project...

db/migrate/yyyymmddhhmmss_create_mezu_messages.rb
db/migrate/yyyymmddhhmmss_create_mezu_readings.rb
config/initializers/mezu.rb
public/mezu/mezu.css

Details about the created migration.

class CreateMezuMessages < ActiveRecord::Migration
  def self.up
    create_table :mezu_messages do |t|
      t.string        :title, :null => false
      t.string        :level, :limit => 10, :null => false
      t.text          :body
      t.string        :locale, :null => false
      t.datetime      :expires_at
      t.references    :messageable, :polymorphic => true, :null => true

      t.timestamps
    end

    add_index :mezu_messages, [:messageable_type, :messageable_id]
  end

  def self.down
    drop_table :mezu_messages
  end
end

class CreateMezuReadings < ActiveRecord::Migration
  def self.up
    create_table :mezu_readings do |t|
      t.references :message, :null => false
      t.references :reader, :polymorphic => true, :null => false
      t.timestamps
    end

    add_index :mezu_readings, :message_id
  end

  def self.down
    drop_table :mezu_readings
  end
end

How to use?

This engine adds on your app the path /mezu, to CRUD your mezu system messages

To protect mezu system messages access on your CRUD, go to config/initializers/mezu.rb file and implement your powerful authentication protection.

Retrieve messages for several object classes

messages = Mezu::Message.list(:user => current_user.id, :group => current_user.group_ids)

Marking message as read

message = Mezu::Message.first
message.read_by!(user)

Listing unread messages for a given user

Mezu::Message.list(:user => current_user.id, :group => current_user.group_ids).unread_by(current_user)

I18n support

If you're handling more than one locale, you can configure which locales you can associate messages with. Just go to config/initializers/mezu.rb and set the available locales:

Mezu.configure do
  config.available_locales = [:en, :"pt-BR"]
end

By default, these will return the I18n.available_locales list.

You can then filter the message with by_locale scope:

Mezu::Message.by_locale(I18n.locale)

Maintainer and Contributors

See on commits!