/rails3-amf

A Rails 3 plugin that provides tight rails amf integration

Primary LanguageRuby

Rails3-amf is a Rails 3 plugin that aims to do what RubyAMF did for Rails 2. It provides extensively customizable ActiveRecord serialization support, simple configuration, and allows AMF calls to any controller you choose. It uses RocketAMF for serialization, providing users with a proven AMF0/3 serializer and deserializer. Because of this, it’s also fully Ruby 1.9 compatible out of the box.

GETTING STARTED:

To get started with rails3-amf, all you need to do is add the following two lines to your gemfile. RocketAMF will need to be pulled from git for now, as there are several necessary updates that have been made to it to allow rails3-amf to work properly.

gem 'RocketAMF', :git => 'git://github.com/warhammerkid/rocket-amf.git'
gem 'rails3-amf', :git => 'git://github.com/warhammerkid/rails3-amf.git'

Then, make sure that your controller will respond to amf by adding :amf to your respond_to, and you should be all ready to go with an AMF gateway available at your-site.com/amf. ActiveRecord objects will automatically be serialized with all attributes and no relations, but that can be easilly adjusted through the standard serialization options for ActiveRecord and ActiveModel serialization.

class UserController < ApplicationController
  respond_to :html, :amf

  def getUser
    @user = User.first
    respond_with(@user) do |format|
      format.amf { render :amf => @user.to_amf(:except => [:updated_at, :created_at], :include => [:courses]) }
    end
  end
end

CONFIGURATION:

Rails3-amf has several configuration options. The gateway path, which defaults to “/amf” can be changed to anything you choose. You can map method call arguments by index to named params in your controllers. Finally, there’s the ability to specify flash->ruby class name mappings.

Example:

config.rails3amf.gateway_path = "/rubyamf/gateway"
config.rails3amf.class_mapping do |m|
  m.map :as => 'Test::User', :ruby => 'User'
  m.map :as => 'vo.Course', :ruby => 'Course'
end
config.rails3amf.map_params :controller => 'UserController', :action => 'getUser', :params => [:session_id]

LICENSE:

(The MIT License)

Copyright © 2010 Stephen Augenstein

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.