Sha256: 22c9ab8ed72e8b429311d469e79d4f316402139234855cd1dbb1d82a31c8b31d

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

= acts_as_serializable

by Birkir A. Barkarson <birkirb@stoicviking.net>

== Description

A gem/rails plugin for handling versioning of serialization methods (to_xml, to_json).
Uses the builder pattern for a one stop multi-format serialization method, which can be
versioned in-class, in a module or in seperately managed class files.

== Installation from source

  git clone git://github.com/birkirb/acts_as_serializable.git
  cd acts_as_serializable
  rake install

=== Gem Installation

  gem install birkirb-acts_as_serializable --source http://gems.github.com

== Examples

First:

  require 'rubygems'
  require 'acts_as_serializable'


Define your own serialization method:

  class SimpleClass
    include Serializable
    acts_as_serializable

    def serialize(builder, options)
      builder.root do
        builder.text 'hello world'
      end
    end
  end

  SimpleClass.new.to_xml => "<root><text>hello world</text></root>"
  SimpleClass.new.to_hash => {:text=>"hello world"}
  SimpleClass.new.to_json => "{\"text\": \"hello world\"}"

Use versioned serialization methods:

  class SimpleClass
    include Serializable

    def serialize_to_version_1_0(builder, options)
      builder.root do
        builder.text 'hello world'
      end
    end

    def serialize_to_version_2_0(builder, options)
      builder.texts do
        builder.text "It's a brave new world"
      end
    end

    acts_as_serializable
  end

  SimpleClass.new.to_xml => "<texts><text>It's a brave new world</text></texts>" 
  SimpleClass.new.to_hash(:version => '1.0') => {:text=>"hello world"}

Use classes containing versioned serialization methods:

  WIP

== Copyright

Author::    Birkir A. Barkarson <birkirb@stoicviking.net>
Copyright:: Copyright (c) 2009
License::   MIT License

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
birkirb-acts_as_serializable-0.1.0 README.rdoc
birkirb-acts_as_serializable-0.1.1 README.rdoc